about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-06-22 12:39:44 +0200
committerMichael Vetter <jubalh@iodoru.org>2022-06-22 12:39:44 +0200
commit3f26dd6be98eca05d429693fe54eb38713af72ff (patch)
treec1b39d6cab37545bce3405d1e4325a942a0e8baa
parent6147a1342d4cda8cb5c15d1453d48dc028c2b24d (diff)
downloadprofani-tty-3f26dd6be98eca05d429693fe54eb38713af72ff.tar.gz
Let user change log level while running
`/log level INFO|DEBUG|WARN|ERROR` is now available.
Looks like this solves a TODO (see removed comment in source) from 2013
:-)

Works only with default log file. Not with user provided log file during
start up via the -f parameter.

Fix https://github.com/profanity-im/profanity/issues/1627
-rw-r--r--src/command/cmd_ac.c1
-rw-r--r--src/command/cmd_defs.c6
-rw-r--r--src/command/cmd_funcs.c14
3 files changed, 17 insertions, 4 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index d8121d65..b945528a 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -391,6 +391,7 @@ cmd_ac_init(void)
     autocomplete_add(log_ac, "rotate");
     autocomplete_add(log_ac, "shared");
     autocomplete_add(log_ac, "where");
+    autocomplete_add(log_ac, "level");
 
     autoaway_ac = autocomplete_new();
     autocomplete_add(autoaway_ac, "mode");
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 2eaec284..8c8143fe 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -1884,14 +1884,16 @@ static struct cmd_t command_defs[] = {
               "/log where",
               "/log rotate on|off",
               "/log maxsize <bytes>",
-              "/log shared on|off")
+              "/log shared on|off",
+              "/log level INFO|DEBUG|WARN|ERROR")
       CMD_DESC(
               "Manage profanity log settings.")
       CMD_ARGS(
               { "where", "Show the current log file location." },
               { "rotate on|off", "Rotate log, default on. Does not take effect if you specified a filename yourself when starting Profanity." },
               { "maxsize <bytes>", "With rotate enabled, specifies the max log size, defaults to 1048580 (1MB)." },
-              { "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log filename. Does not take effect if you specified a filename yourself when starting Profanity." })
+              { "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log filename. Does not take effect if you specified a filename yourself when starting Profanity." },
+              {"level INFO|DEBUG|WARN|EFFOR", "Set the log level. Default is INFO. Only works with default log file, not with user provided log file during startup via -f." })
       CMD_NOEXAMPLES
     },
 
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 4edc7c16..fbea6bc2 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -6495,9 +6495,19 @@ cmd_log(ProfWin* window, const char* const command, gchar** args)
         return TRUE;
     }
 
-    cons_bad_cmd_usage(command);
+    if (strcmp(subcmd, "level") == 0) {
+        if (g_strcmp0(value, "INFO") == 0 || g_strcmp0(value, "DEBUG") == 0 || g_strcmp0(value, "WARN") == 0 || g_strcmp0(value, "ERROR") == 0) {
+
+            log_level_t prof_log_level = log_level_from_string(value);
+            log_close();
+            log_init(prof_log_level, NULL);
 
-    /* TODO: make 'level' subcommand for debug level */
+            cons_show("Log level changed to: %s.", value);
+            return TRUE;
+        }
+    }
+
+    cons_bad_cmd_usage(command);
 
     return TRUE;
 }