Allow to set the log level via options
This commit is contained in:
parent
38dced7591
commit
280ec456a4
@ -444,6 +444,12 @@ WM_CLASS). There should be no need to modify this setting for regular use.
|
||||
Display a notification on startup. This is usually used for debugging and there
|
||||
shouldn't be any need to use this option.
|
||||
|
||||
=item B<verbosity> (values: 'crit', 'warn', 'mesg', 'info', 'debug' default 'mesg')
|
||||
|
||||
Do not display log messages, which have lower precedence than specified
|
||||
verbosity. This won't affect printing notifications on the terminal. Use
|
||||
the '-print' option for this.
|
||||
|
||||
=item B<force_xinerama> (values: [true/false], default: false)
|
||||
|
||||
Use the Xinerama extension instead of RandR for multi-monitor support. This
|
||||
|
9
dunstrc
9
dunstrc
@ -198,6 +198,15 @@
|
||||
# automatically after a crash.
|
||||
startup_notification = false
|
||||
|
||||
# Manage dunst's desire for talking
|
||||
# Can be one of the following values:
|
||||
# crit: Critical features. Dunst aborts
|
||||
# warn: Only non-fatal warnings
|
||||
# mesg: Important Messages
|
||||
# info: all unimportant stuff
|
||||
# debug: all less than unimportant stuff
|
||||
verbosity = mesg
|
||||
|
||||
### Legacy
|
||||
|
||||
# Use the Xinerama extension instead of RandR for multi-monitor support.
|
||||
|
@ -132,6 +132,10 @@ int dunst_main(int argc, char *argv[])
|
||||
print_version();
|
||||
}
|
||||
|
||||
char *verbosity = cmdline_get_string("-verbosity", NULL, "Minimum level for message");
|
||||
log_set_level_from_string(verbosity);
|
||||
g_free(verbosity);
|
||||
|
||||
char *cmdline_config_path;
|
||||
cmdline_config_path =
|
||||
cmdline_get_string("-conf/-config", NULL,
|
||||
|
40
src/log.c
40
src/log.c
@ -4,6 +4,8 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
static GLogLevelFlags log_level = G_LOG_LEVEL_WARNING;
|
||||
|
||||
static const char *log_level_to_string(GLogLevelFlags level)
|
||||
{
|
||||
switch (level) {
|
||||
@ -17,6 +19,38 @@ static const char *log_level_to_string(GLogLevelFlags level)
|
||||
}
|
||||
}
|
||||
|
||||
void log_set_level_from_string(const char *level)
|
||||
{
|
||||
if (!level)
|
||||
return;
|
||||
|
||||
if (g_ascii_strcasecmp(level, "critical") == 0)
|
||||
log_level = G_LOG_LEVEL_CRITICAL;
|
||||
else if (g_ascii_strcasecmp(level, "crit") == 0)
|
||||
log_level = G_LOG_LEVEL_CRITICAL;
|
||||
else if (g_ascii_strcasecmp(level, "warning") == 0)
|
||||
log_level = G_LOG_LEVEL_WARNING;
|
||||
else if (g_ascii_strcasecmp(level, "warn") == 0)
|
||||
log_level = G_LOG_LEVEL_WARNING;
|
||||
else if (g_ascii_strcasecmp(level, "message") == 0)
|
||||
log_level = G_LOG_LEVEL_MESSAGE;
|
||||
else if (g_ascii_strcasecmp(level, "mesg") == 0)
|
||||
log_level = G_LOG_LEVEL_MESSAGE;
|
||||
else if (g_ascii_strcasecmp(level, "info") == 0)
|
||||
log_level = G_LOG_LEVEL_INFO;
|
||||
else if (g_ascii_strcasecmp(level, "debug") == 0)
|
||||
log_level = G_LOG_LEVEL_DEBUG;
|
||||
else if (g_ascii_strcasecmp(level, "deb") == 0)
|
||||
log_level = G_LOG_LEVEL_DEBUG;
|
||||
else
|
||||
LOG_W("Unknown log level: '%s'", level);
|
||||
}
|
||||
|
||||
void log_set_level(GLogLevelFlags level)
|
||||
{
|
||||
log_level = level;
|
||||
}
|
||||
|
||||
/*
|
||||
* Log handling function for GLib's logging wrapper
|
||||
*
|
||||
@ -31,6 +65,12 @@ static void dunst_log_handler(
|
||||
if (testing)
|
||||
return;
|
||||
|
||||
/* if you want to have a debug build, you want to log anything,
|
||||
* unconditionally, without specifying debug log level again */
|
||||
#ifndef DEBUG_BUILD
|
||||
if (log_level < message_level)
|
||||
return;
|
||||
#endif
|
||||
const char *log_level_str =
|
||||
log_level_to_string(message_level & G_LOG_LEVEL_MASK);
|
||||
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
#define DIE(...) do { LOG_C(__VA_ARGS__); exit(EXIT_FAILURE); } while (0)
|
||||
|
||||
void log_set_level(GLogLevelFlags level);
|
||||
void log_set_level_from_string(const char* level);
|
||||
|
||||
void dunst_log_init(bool testing);
|
||||
|
||||
#endif
|
||||
|
@ -106,6 +106,13 @@ void load_settings(char *cmdline_config_path)
|
||||
"Using STATIC_CONFIG is deprecated behavior.");
|
||||
#endif
|
||||
|
||||
log_set_level_from_string(option_get_string(
|
||||
"global",
|
||||
"verbosity", "-verbosity", NULL,
|
||||
"The verbosity to log (one of 'info', 'mesg', 'warn', 'crit')"
|
||||
"The verbosity to log (one of 'crit', 'warn', 'mesg', 'info', 'debug')"
|
||||
));
|
||||
|
||||
settings.per_monitor_dpi = option_get_bool(
|
||||
"experimental",
|
||||
"per_monitor_dpi", NULL, false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user