diff options
-rw-r--r-- | src/command/command.c | 37 | ||||
-rw-r--r-- | src/command/commands.c | 15 | ||||
-rw-r--r-- | src/config/preferences.c | 4 | ||||
-rw-r--r-- | src/config/preferences.h | 3 | ||||
-rw-r--r-- | src/log.c | 8 | ||||
-rw-r--r-- | src/profanity.c | 2 | ||||
-rw-r--r-- | src/ui/console.c | 4 |
7 files changed, 58 insertions, 15 deletions
diff --git a/src/command/command.c b/src/command/command.c index d7cf67e3..89d3e376 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -69,6 +69,7 @@ static char * _connect_autocomplete(char *input, int *size); static char * _statuses_autocomplete(char *input, int *size); static char * _alias_autocomplete(char *input, int *size); static char * _join_autocomplete(char *input, int *size); +static char * _log_autocomplete(char *input, int *size); GHashTable *commands = NULL; @@ -639,11 +640,12 @@ static struct cmd_t command_defs[] = { "/log", cmd_log, parse_args, 2, 2, &cons_log_setting, - { "/log maxsize value", "Manage system logging settings.", - { "/log maxsize value", - "------------------", - "maxsize : When log file size exceeds this value it will be automatically", - " rotated (file will be renamed). Default value is 1048580 (1MB)", + { "/log [property] [value]", "Manage system logging settings.", + { "/log [property] [value]", + "-----------------------", + "Property may be one of:", + "rotate : 'on' or 'off', determines whether the log will be rotated, defaults to 'on'", + "maxsize : When log file size exceeds this value and rotate is enabled, it will be automatically be rotated, defaults to 1048580 (1MB)", NULL } } }, { "/reconnect", @@ -950,6 +952,7 @@ cmd_init(void) log_ac = autocomplete_new(); autocomplete_add(log_ac, "maxsize"); + autocomplete_add(log_ac, "rotate"); autoaway_ac = autocomplete_new(); autocomplete_add(autoaway_ac, "mode"); @@ -1468,8 +1471,8 @@ _cmd_complete_parameters(char *input, int *size) } } - gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins" }; - Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac }; + gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins" }; + Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, size, cmds[i], completers[i]); @@ -1481,7 +1484,7 @@ _cmd_complete_parameters(char *input, int *size) } autocompleter acs[] = { _who_autocomplete, _sub_autocomplete, _notify_autocomplete, - _autoaway_autocomplete, _theme_autocomplete, + _autoaway_autocomplete, _theme_autocomplete, _log_autocomplete, _account_autocomplete, _roster_autocomplete, _group_autocomplete, _bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete, _connect_autocomplete, _statuses_autocomplete, _alias_autocomplete, @@ -1675,6 +1678,24 @@ _autoaway_autocomplete(char *input, int *size) } static char * +_log_autocomplete(char *input, int *size) +{ + char *result = NULL; + + result = autocomplete_param_with_func(input, size, "/log rotate", + prefs_autocomplete_boolean_choice); + if (result != NULL) { + return result; + } + result = autocomplete_param_with_ac(input, size, "/log", log_ac); + if (result != NULL) { + return result; + } + + return NULL; +} + +static char * _autoconnect_autocomplete(char *input, int *size) { char *result = NULL; diff --git a/src/command/commands.c b/src/command/commands.c index fd7523fa..884c26a4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2291,10 +2291,21 @@ cmd_log(gchar **args, struct cmd_help_t help) prefs_set_max_log_size(intval); cons_show("Log maxinum size set to %d bytes", intval); } - } else { - cons_show("Usage: %s", help.usage); + return TRUE; } + if (strcmp(subcmd, "rotate") == 0) { + if (value == NULL) { + cons_show("Usage: %s", help.usage); + return TRUE; + } else { + return _cmd_set_boolean_preference(value, help, + "Log rotate", PREF_LOG_ROTATE); + } + } + + cons_show("Usage: %s", help.usage); + /* TODO: make 'level' subcommand for debug level */ return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index 6f085ba3..7327cd8e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -393,6 +393,7 @@ _get_group(preference_t pref) case PREF_CHLOG: case PREF_GRLOG: case PREF_OTR_LOG: + case PREF_LOG_ROTATE: return PREF_GROUP_LOGGING; case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_MODE: @@ -464,6 +465,8 @@ _get_key(preference_t pref) return "otr"; case PREF_OTR_WARN: return "otr.warn"; + case PREF_LOG_ROTATE: + return "rotate"; default: return NULL; } @@ -477,6 +480,7 @@ _get_default_boolean(preference_t pref) case PREF_TITLEBAR: case PREF_OTR_WARN: case PREF_AUTOAWAY_CHECK: + case PREF_LOG_ROTATE: return TRUE; default: return FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index 2c783f4d..266fccc5 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -62,7 +62,8 @@ typedef enum { PREF_AUTOAWAY_MESSAGE, PREF_CONNECT_ACCOUNT, PREF_OTR_LOG, - PREF_OTR_WARN + PREF_OTR_WARN, + PREF_LOG_ROTATE } preference_t; typedef struct prof_alias_t { diff --git a/src/log.c b/src/log.c index 68ba476c..b0745392 100644 --- a/src/log.c +++ b/src/log.c @@ -154,9 +154,11 @@ log_msg(log_level_t level, const char * const area, const char * const msg) fflush(logp); g_free(date_fmt); - result = ftell(logp); - if (result != -1 && result >= prefs_get_max_log_size()) { - _rotate_log_file(); + if (prefs_get_boolean(PREF_LOG_ROTATE)) { + result = ftell(logp); + if (result != -1 && result >= prefs_get_max_log_size()) { + _rotate_log_file(); + } } } } diff --git a/src/profanity.c b/src/profanity.c index 540b6085..95355670 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -256,6 +256,7 @@ _init(const int disable_tls, char *log_level) signal(SIGPIPE, SIG_IGN); _create_directories(); log_level_t prof_log_level = log_level_from_string(log_level); + prefs_load(); log_init(prof_log_level); if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION @@ -268,7 +269,6 @@ _init(const int disable_tls, char *log_level) } chat_log_init(); groupchat_log_init(); - prefs_load(); accounts_load(); gchar *theme = prefs_get_string(PREF_THEME); theme_init(theme); diff --git a/src/ui/console.c b/src/ui/console.c index 86ee7909..aedb637d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1223,6 +1223,10 @@ static void _cons_log_setting(void) { cons_show("Max log size (/log maxsize) : %d bytes", prefs_get_max_log_size()); + if (prefs_get_boolean(PREF_LOG_ROTATE)) + cons_show("Log rotation (/log rotate) : ON"); + else + cons_show("Log rotation (/log rotate) : OFF"); } static void |