feat: make /log level work with non-default files

This commit is contained in:
2025-10-13 20:47:34 +02:00
parent fac1e224bc
commit ad95edb2b9
4 changed files with 7 additions and 6 deletions

View File

@@ -1902,9 +1902,9 @@ static const struct cmd_t command_defs[] = {
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 10485760 (10MB)." },
{ "maxsize <bytes>", "With rotate enabled, specifies the max log size, defaults to 10485760 (10MiB)." },
{ "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|ERROR", "Set the log level. Default is INFO. Only works with default log file, not with user provided log file during startup via -f." })
{ "level INFO|DEBUG|WARN|ERROR", "Set the log level. Default is INFO." })
},
{ CMD_PREAMBLE("/carbons",

View File

@@ -6271,10 +6271,11 @@ cmd_log(ProfWin* window, const char* const command, gchar** args)
if (strcmp(subcmd, "level") == 0) {
log_level_t prof_log_level;
if (log_level_from_string(value, &prof_log_level) == 0) {
auto_char char* log_file = strdup(get_log_file_location());
log_close();
log_init(prof_log_level, NULL);
log_init(prof_log_level, log_file);
cons_show("Log level changed to: %s.", value);
cons_show("Log level changed to: %s (log file: %s).", value, log_file ? log_file : "[default]");
return TRUE;
}
}

View File

@@ -186,7 +186,7 @@ log_error(const char* const msg, ...)
}
void
log_init(log_level_t filter, char* log_file)
log_init(log_level_t filter, const char* const log_file)
{
level_filter = filter;

View File

@@ -50,7 +50,7 @@ typedef enum {
PROF_LEVEL_ERROR
} log_level_t;
void log_init(log_level_t filter, char* log_file);
void log_init(log_level_t filter, const char* const log_file);
log_level_t log_get_filter(void);
void log_close(void);
const gchar* get_log_file_location(void);