diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-12-11 10:40:10 +0100 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-12-11 10:40:10 +0100 |
commit | a8990014e22f4735890a3473aab87a05245a9822 (patch) | |
tree | 90e394a112fc0579d1ea65b70e475b3c632f24f8 /src | |
parent | 560a15e2a90f5ab10859cf88fb619367e7fb9b26 (diff) | |
download | profani-tty-a8990014e22f4735890a3473aab87a05245a9822.tar.gz |
Use whole path as logfile when defined via -f
`profanity -f my` created ~/.local/share/profanity/logs/my.log`. It would be nicer if one could define the actual path, so one can choose another directory or even use /dev/null. Fixes https://github.com/profanity-im/profanity/issues/1442
Diffstat (limited to 'src')
-rw-r--r-- | src/config/files.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/config/files.c b/src/config/files.c index 72b192e4..b6a8d490 100644 --- a/src/config/files.c +++ b/src/config/files.c @@ -116,20 +116,26 @@ char* files_get_log_file(const char* const log_file) { gchar* xdg_data = _files_get_xdg_data_home(); - GString* logfile = g_string_new(xdg_data); + GString* logfile; if (log_file) { - g_string_append(logfile, "/profanity/logs/"); - g_string_append(logfile, log_file); + gchar *log_path = g_path_get_dirname(log_file); + if (!mkdir_recursive(log_path)) { + log_error("Error while creating directory %s", log_path); + } + g_free(log_path); + + logfile = g_string_new(log_file); } else { + logfile = g_string_new(xdg_data); g_string_append(logfile, "/profanity/logs/profanity"); - } - if (!prefs_get_boolean(PREF_LOG_SHARED)) { - g_string_append_printf(logfile, "%d", getpid()); - } + if (!prefs_get_boolean(PREF_LOG_SHARED)) { + g_string_append_printf(logfile, "%d", getpid()); + } - g_string_append(logfile, ".log"); + g_string_append(logfile, ".log"); + } char* result = g_strdup(logfile->str); |