diff --git a/docs/dunst.pod b/docs/dunst.pod index 0973fa8..d2c7a0b 100644 --- a/docs/dunst.pod +++ b/docs/dunst.pod @@ -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 (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 (values: [true/false], default: false) Use the Xinerama extension instead of RandR for multi-monitor support. This diff --git a/dunstrc b/dunstrc index dbe7eab..0f4c4aa 100644 --- a/dunstrc +++ b/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. diff --git a/src/dunst.c b/src/dunst.c index 18e4536..53fb2fc 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -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, diff --git a/src/log.c b/src/log.c index a99b7fe..ad777f6 100644 --- a/src/log.c +++ b/src/log.c @@ -4,6 +4,8 @@ #include +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); diff --git a/src/log.h b/src/log.h index 1bfc921..3ca6e9d 100644 --- a/src/log.h +++ b/src/log.h @@ -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 diff --git a/src/settings.c b/src/settings.c index 8f20476..e8b685f 100644 --- a/src/settings.c +++ b/src/settings.c @@ -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, diff --git a/src/test b/src/test new file mode 100755 index 0000000..66605e6 Binary files /dev/null and b/src/test differ