Add command line and config file option log-level

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-12-20 01:21:51 +00:00
parent 1bcd7f2f7a
commit d9409ae2c9
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
5 changed files with 24 additions and 1 deletions

View File

@ -76,6 +76,9 @@ OPTIONS
*-S*:: *-S*::
Enable synchronous X operation (for debugging). 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-xerrors*::
Show all X errors (for debugging). Show all X errors (for debugging).

View File

@ -2607,6 +2607,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
{ "version", no_argument, NULL, 318 }, { "version", no_argument, NULL, 318 },
{ "no-x-selection", no_argument, NULL, 319 }, { "no-x-selection", no_argument, NULL, 319 },
{ "no-name-pixmap", no_argument, NULL, 320 }, { "no-name-pixmap", no_argument, NULL, 320 },
{ "log-level", required_argument, NULL, 321 },
{ "reredir-on-root-change", no_argument, NULL, 731 }, { "reredir-on-root-change", no_argument, NULL, 731 },
{ "glx-reinit-on-root-change", no_argument, NULL, 732 }, { "glx-reinit-on-root-change", no_argument, NULL, 732 },
{ "monitor-repaint", no_argument, NULL, 800 }, { "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" " removed in the future. If you really need this feature, please report\n"
"an issue to let us know\n"); "an issue to let us know\n");
break; 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(319, no_x_selection);
P_CASEBOOL(731, reredir_on_root_change); P_CASEBOOL(731, reredir_on_root_change);
P_CASEBOOL(732, glx_reinit_on_root_change); P_CASEBOOL(732, glx_reinit_on_root_change);

View File

@ -281,6 +281,15 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable,
// --backend // --backend
if (config_lookup_string(&cfg, "backend", &sval) && !parse_backend(ps, sval)) if (config_lookup_string(&cfg, "backend", &sval) && !parse_backend(ps, sval))
exit(1); 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 // --sw-opti
lcfg_lookup_bool(&cfg, "sw-opti", &ps->o.sw_opti); lcfg_lookup_bool(&cfg, "sw-opti", &ps->o.sw_opti);
// --use-ewmh-active-win // --use-ewmh-active-win

View File

@ -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) if (strcasecmp(str, "TRACE") == 0)
return LOG_LEVEL_TRACE; return LOG_LEVEL_TRACE;
else if (strcasecmp(str, "DEBUG") == 0) else if (strcasecmp(str, "DEBUG") == 0)

View File

@ -54,6 +54,7 @@ attr_malloc struct log *log_new(void);
attr_nonnull_all void log_destroy(struct log *); attr_nonnull_all void log_destroy(struct log *);
attr_nonnull(1) void log_set_level(struct log *l, int level); 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_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; extern thread_local struct log *tls_logger;