Skip to content

Commit 499d15f

Browse files
committed
Improve logging facilities
Signed-off-by: Tin Švagelj <[email protected]>
1 parent cc5b621 commit 499d15f

File tree

13 files changed

+333
-75
lines changed

13 files changed

+333
-75
lines changed

cmake/ConkyPlatformChecks.cmake

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,9 @@ if(BUILD_COLOUR_NAME_MAP)
679679
mark_as_advanced(APP_GPERF)
680680
endif(BUILD_COLOUR_NAME_MAP)
681681

682-
if(CMAKE_BUILD_TYPE MATCHES "Debug")
683-
set(DEBUG true)
684-
endif(CMAKE_BUILD_TYPE MATCHES "Debug")
685-
686682
# The version numbers are simply derived from the date and number of commits
687683
# since start of month
688-
if(DEBUG)
684+
if(CMAKE_BUILD_TYPE MATCHES "Debug")
689685
execute_process(COMMAND ${APP_GIT} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git
690686
log --since=${VERSION_MAJOR}-${VERSION_MINOR}-01
691687
--pretty=oneline
@@ -694,4 +690,4 @@ if(DEBUG)
694690
RESULT_VARIABLE RETVAL
695691
OUTPUT_VARIABLE COMMIT_COUNT
696692
OUTPUT_STRIP_TRAILING_WHITESPACE)
697-
endif(DEBUG)
693+
endif()

cmake/config.h.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#ifndef _conky_config_h_
77
#define _conky_config_h_
88

9-
#cmakedefine DEBUG
10-
119
#define SYSTEM_NAME "@CMAKE_SYSTEM_NAME@"
1210
#define PACKAGE_NAME "@PROJECT_NAME@"
1311
#define VERSION "@VERSION@"

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ execute_process(
6464

6565
set(conky_sources
6666
${conky_sources}
67+
logging.cc
6768
c++wrap.cc
6869
c++wrap.hh
6970
colour-settings.cc

src/ccurl_thread.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "logging.h"
3030
#include "text_object.h"
3131

32-
#ifdef DEBUG
32+
#ifndef NDEBUG
3333
#include <assert.h>
34-
#endif /* DEBUG */
34+
#endif /* NDEBUG */
3535

3636
#include <curl/easy.h>
3737

src/common.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ double loadgraphval(struct text_object *obj) {
365365
uint8_t cpu_percentage(struct text_object *obj) {
366366
if (static_cast<unsigned int>(obj->data.i) > info.cpu_count) {
367367
NORM_ERR("obj->data.i %i info.cpu_count %i", obj->data.i, info.cpu_count);
368-
CRIT_ERR("attempting to use more CPUs than you have!");
368+
USER_ERR("attempting to use more CPUs than you have!");
369369
}
370370
if (info.cpu_usage != nullptr) {
371371
return round_to_positive_int(info.cpu_usage[obj->data.i] * 100.0);
@@ -376,7 +376,7 @@ uint8_t cpu_percentage(struct text_object *obj) {
376376
double cpu_barval(struct text_object *obj) {
377377
if (static_cast<unsigned int>(obj->data.i) > info.cpu_count) {
378378
NORM_ERR("obj->data.i %i info.cpu_count %i", obj->data.i, info.cpu_count);
379-
CRIT_ERR("attempting to use more CPUs than you have!");
379+
USER_ERR("attempting to use more CPUs than you have!");
380380
}
381381
if (info.cpu_usage != nullptr) { return info.cpu_usage[obj->data.i]; }
382382
return 0.;

src/conky.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ const char builtin_config_magic[] = "==builtin==";
171171
// #define SIGNAL_BLOCKING
172172
#undef SIGNAL_BLOCKING
173173

174-
/* debugging level, used by logging.h */
175-
int global_debug_level = 0;
176-
177174
/* disable inotify auto reload feature if desired */
178175
static conky::simple_config_setting<bool> disable_auto_reload(
179176
"disable_auto_reload", false, false);
@@ -1915,6 +1912,7 @@ void clean_up(void) {
19151912

19161913
conky::cleanup_config_settings(*state);
19171914
state.reset();
1915+
conky::log::terminate_logging();
19181916
}
19191917

19201918
void handle_terminate() {
@@ -2216,31 +2214,31 @@ void initialisation(int argc, char **argv) {
22162214
case 'u':
22172215
state->pushnumber(strtod(optarg, &conv_end));
22182216
if (*conv_end != 0) {
2219-
CRIT_ERR("'%s' is an invalid update interval", optarg);
2217+
USER_ERR("'%s' is an invalid update interval", optarg);
22202218
}
22212219
update_interval.lua_set(*state);
22222220
break;
22232221

22242222
case 'i':
22252223
state->pushinteger(strtol(optarg, &conv_end, 10));
22262224
if (*conv_end != 0) {
2227-
CRIT_ERR("'%s' is an invalid number of update times", optarg);
2225+
USER_ERR("'%s' is an invalid number of update times", optarg);
22282226
}
22292227
total_run_times.lua_set(*state);
22302228
break;
22312229
#ifdef BUILD_X11
22322230
case 'x':
22332231
state->pushinteger(strtol(optarg, &conv_end, 10));
22342232
if (*conv_end != 0) {
2235-
CRIT_ERR("'%s' is an invalid value for the X-position", optarg);
2233+
USER_ERR("'%s' is an invalid value for the X-position", optarg);
22362234
}
22372235
gap_x.lua_set(*state);
22382236
break;
22392237

22402238
case 'y':
22412239
state->pushinteger(strtol(optarg, &conv_end, 10));
22422240
if (*conv_end != 0) {
2243-
CRIT_ERR("'%s' is a wrong value for the Y-position", optarg);
2241+
USER_ERR("'%s' is a wrong value for the Y-position", optarg);
22442242
}
22452243
gap_y.lua_set(*state);
22462244
break;

src/core.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
20342034
END {
20352035
auto *buf = static_cast<char *>(malloc(text_buffer_size.get(*state)));
20362036

2037-
NORM_ERR("unknown variable '$%s'", s);
2037+
LOG_WARNING("unknown variable '$%s'", s);
20382038
snprintf(buf, text_buffer_size.get(*state), "${%s}", s);
20392039
obj_be_plain_text(obj, buf);
20402040
free(buf);

src/darwin.mm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@
8888
#endif
8989

9090
/* debugging defines */
91-
#define DEBUG_MODE
91+
#undef NDEBUG
9292

9393
/* (E)nhanced printf */
94-
#ifdef DEBUG_MODE
94+
#ifndef NDEBUG
9595
#include <cstdarg>
9696
void eprintf(const char *fmt, ...) {
9797
va_list args;
@@ -928,9 +928,8 @@ void get_cpu_count() {
928928
/*
929929
* Allocate ncpus+1 slots because cpu_usage[0] is overall usage.
930930
*/
931-
info.cpu_usage =
932-
static_cast<float *>(malloc((info.cpu_count + 1) * sizeof(float)));
933-
if (info.cpu_usage == nullptr) { CRIT_ERR("malloc"); }
931+
info.cpu_usage = new float[info.cpu_count + 1];
932+
if (info.cpu_usage == nullptr) { CRIT_ERR("unable to allocate cpu_usage for %d cores", info.cpu_count + 1); }
934933
}
935934
}
936935

src/display-output.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
namespace conky {
3737

3838
inline void log_missing(const char *name, const char *flag) {
39-
DBGP(
39+
LOG_INFO(
4040
"%s display output disabled. Enable by recompiling with '%s' "
4141
"flag enabled.",
4242
name, flag);
@@ -87,7 +87,9 @@ bool initialize_display_outputs() {
8787
register_output<output_t::X11>(outputs);
8888
register_output<output_t::WAYLAND>(outputs);
8989

90-
for (auto out : outputs) { NORM_ERR("FOUND: %s", out->name.c_str()); }
90+
for (auto out : outputs) {
91+
LOG_TRACE("%s output display found.", out->name.c_str());
92+
}
9193

9294
// Sort display outputs by descending priority, to try graphical ones first.
9395
sort(outputs.begin(), outputs.end(), &display_output_base::priority_compare);

src/freebsd.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@
6767
#define KELVTOC(x) ((x - 2732) / 10.0)
6868
#define MAXSHOWDEVS 16
6969

70-
#if 0
71-
#define FREEBSD_DEBUG
72-
#endif
73-
7470
kvm_t *kd;
7571
std::mutex kvm_proc_mutex;
7672

0 commit comments

Comments
 (0)