diff --git a/man/compton.1.asciidoc b/man/compton.1.asciidoc index acda576..7d48a43 100644 --- a/man/compton.1.asciidoc +++ b/man/compton.1.asciidoc @@ -76,6 +76,9 @@ OPTIONS *-S*:: Enable synchronous X operation (for debugging). +*--log-level*:: + Set the log level. Possible values are "TRACE", "DEBUG", "INFO", "WARN", "ERROR", in increasing level of importance. Case doesn't matter. + *--show-all-xerrors*:: Show all X errors (for debugging). diff --git a/src/compton.c b/src/compton.c index 15b866c..4cd3b71 100644 --- a/src/compton.c +++ b/src/compton.c @@ -2607,6 +2607,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { { "version", no_argument, NULL, 318 }, { "no-x-selection", no_argument, NULL, 319 }, { "no-name-pixmap", no_argument, NULL, 320 }, + { "log-level", required_argument, NULL, 321 }, { "reredir-on-root-change", no_argument, NULL, 731 }, { "glx-reinit-on-root-change", no_argument, NULL, 732 }, { "monitor-repaint", no_argument, NULL, 800 }, @@ -2895,6 +2896,15 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { " removed in the future. If you really need this feature, please report\n" "an issue to let us know\n"); break; + case 321: { + enum log_level tmp_level = string_to_log_level(optarg); + if (tmp_level == LOG_LEVEL_INVALID) { + log_warn("Invalid log level, defaults to WARN"); + } else { + log_set_level_tls(tmp_level); + } + break; + } P_CASEBOOL(319, no_x_selection); P_CASEBOOL(731, reredir_on_root_change); P_CASEBOOL(732, glx_reinit_on_root_change); diff --git a/src/config_libconfig.c b/src/config_libconfig.c index 9f9817f..d4fa5a2 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -281,6 +281,15 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable, // --backend if (config_lookup_string(&cfg, "backend", &sval) && !parse_backend(ps, sval)) exit(1); + // --log-level + if (config_lookup_string(&cfg, "log-level", &sval)) { + auto level = string_to_log_level(sval); + if (level == LOG_LEVEL_INVALID) { + log_warn("Invalid log level, defaults to WARN"); + } else { + log_set_level_tls(level); + } + } // --sw-opti lcfg_lookup_bool(&cfg, "sw-opti", &ps->o.sw_opti); // --use-ewmh-active-win diff --git a/src/log.c b/src/log.c index 839071e..7031ee9 100644 --- a/src/log.c +++ b/src/log.c @@ -54,7 +54,7 @@ static attr_const const char *log_level_to_string(enum log_level level) { } } -attr_const enum log_level string_to_log_level(const char *str) { +enum log_level string_to_log_level(const char *str) { if (strcasecmp(str, "TRACE") == 0) return LOG_LEVEL_TRACE; else if (strcasecmp(str, "DEBUG") == 0) diff --git a/src/log.h b/src/log.h index a60fd49..55392da 100644 --- a/src/log.h +++ b/src/log.h @@ -54,6 +54,7 @@ attr_malloc struct log *log_new(void); attr_nonnull_all void log_destroy(struct log *); attr_nonnull(1) void log_set_level(struct log *l, int level); attr_nonnull_all void log_add_target(struct log *, struct log_target *); +attr_const enum log_level string_to_log_level(const char *); extern thread_local struct log *tls_logger;