1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added /log rotate option

This commit is contained in:
James Booth 2014-04-13 20:41:11 +01:00
parent bc6f8ceb3a
commit a4a23fdf68
7 changed files with 58 additions and 15 deletions

View File

@ -69,6 +69,7 @@ static char * _connect_autocomplete(char *input, int *size);
static char * _statuses_autocomplete(char *input, int *size); static char * _statuses_autocomplete(char *input, int *size);
static char * _alias_autocomplete(char *input, int *size); static char * _alias_autocomplete(char *input, int *size);
static char * _join_autocomplete(char *input, int *size); static char * _join_autocomplete(char *input, int *size);
static char * _log_autocomplete(char *input, int *size);
GHashTable *commands = NULL; GHashTable *commands = NULL;
@ -639,11 +640,12 @@ static struct cmd_t command_defs[] =
{ "/log", { "/log",
cmd_log, parse_args, 2, 2, &cons_log_setting, cmd_log, parse_args, 2, 2, &cons_log_setting,
{ "/log maxsize value", "Manage system logging settings.", { "/log [property] [value]", "Manage system logging settings.",
{ "/log maxsize value", { "/log [property] [value]",
"------------------", "-----------------------",
"maxsize : When log file size exceeds this value it will be automatically", "Property may be one of:",
" rotated (file will be renamed). Default value is 1048580 (1MB)", "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 } } }, NULL } } },
{ "/reconnect", { "/reconnect",
@ -950,6 +952,7 @@ cmd_init(void)
log_ac = autocomplete_new(); log_ac = autocomplete_new();
autocomplete_add(log_ac, "maxsize"); autocomplete_add(log_ac, "maxsize");
autocomplete_add(log_ac, "rotate");
autoaway_ac = autocomplete_new(); autoaway_ac = autocomplete_new();
autocomplete_add(autoaway_ac, "mode"); autocomplete_add(autoaway_ac, "mode");
@ -1468,8 +1471,8 @@ _cmd_complete_parameters(char *input, int *size)
} }
} }
gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins" }; gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins" };
Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac }; Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac };
for (i = 0; i < ARRAY_SIZE(cmds); i++) { for (i = 0; i < ARRAY_SIZE(cmds); i++) {
result = autocomplete_param_with_ac(input, size, cmds[i], completers[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, autocompleter acs[] = { _who_autocomplete, _sub_autocomplete, _notify_autocomplete,
_autoaway_autocomplete, _theme_autocomplete, _autoaway_autocomplete, _theme_autocomplete, _log_autocomplete,
_account_autocomplete, _roster_autocomplete, _group_autocomplete, _account_autocomplete, _roster_autocomplete, _group_autocomplete,
_bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete, _bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete,
_connect_autocomplete, _statuses_autocomplete, _alias_autocomplete, _connect_autocomplete, _statuses_autocomplete, _alias_autocomplete,
@ -1674,6 +1677,24 @@ _autoaway_autocomplete(char *input, int *size)
return NULL; return NULL;
} }
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 * static char *
_autoconnect_autocomplete(char *input, int *size) _autoconnect_autocomplete(char *input, int *size)
{ {

View File

@ -2291,10 +2291,21 @@ cmd_log(gchar **args, struct cmd_help_t help)
prefs_set_max_log_size(intval); prefs_set_max_log_size(intval);
cons_show("Log maxinum size set to %d bytes", intval); cons_show("Log maxinum size set to %d bytes", intval);
} }
} else { return TRUE;
cons_show("Usage: %s", help.usage);
} }
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 */ /* TODO: make 'level' subcommand for debug level */
return TRUE; return TRUE;

View File

@ -393,6 +393,7 @@ _get_group(preference_t pref)
case PREF_CHLOG: case PREF_CHLOG:
case PREF_GRLOG: case PREF_GRLOG:
case PREF_OTR_LOG: case PREF_OTR_LOG:
case PREF_LOG_ROTATE:
return PREF_GROUP_LOGGING; return PREF_GROUP_LOGGING;
case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_CHECK:
case PREF_AUTOAWAY_MODE: case PREF_AUTOAWAY_MODE:
@ -464,6 +465,8 @@ _get_key(preference_t pref)
return "otr"; return "otr";
case PREF_OTR_WARN: case PREF_OTR_WARN:
return "otr.warn"; return "otr.warn";
case PREF_LOG_ROTATE:
return "rotate";
default: default:
return NULL; return NULL;
} }
@ -477,6 +480,7 @@ _get_default_boolean(preference_t pref)
case PREF_TITLEBAR: case PREF_TITLEBAR:
case PREF_OTR_WARN: case PREF_OTR_WARN:
case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_CHECK:
case PREF_LOG_ROTATE:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;

View File

@ -62,7 +62,8 @@ typedef enum {
PREF_AUTOAWAY_MESSAGE, PREF_AUTOAWAY_MESSAGE,
PREF_CONNECT_ACCOUNT, PREF_CONNECT_ACCOUNT,
PREF_OTR_LOG, PREF_OTR_LOG,
PREF_OTR_WARN PREF_OTR_WARN,
PREF_LOG_ROTATE
} preference_t; } preference_t;
typedef struct prof_alias_t { typedef struct prof_alias_t {

View File

@ -154,9 +154,11 @@ log_msg(log_level_t level, const char * const area, const char * const msg)
fflush(logp); fflush(logp);
g_free(date_fmt); g_free(date_fmt);
result = ftell(logp); if (prefs_get_boolean(PREF_LOG_ROTATE)) {
if (result != -1 && result >= prefs_get_max_log_size()) { result = ftell(logp);
_rotate_log_file(); if (result != -1 && result >= prefs_get_max_log_size()) {
_rotate_log_file();
}
} }
} }
} }

View File

@ -256,6 +256,7 @@ _init(const int disable_tls, char *log_level)
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
_create_directories(); _create_directories();
log_level_t prof_log_level = log_level_from_string(log_level); log_level_t prof_log_level = log_level_from_string(log_level);
prefs_load();
log_init(prof_log_level); log_init(prof_log_level);
if (strcmp(PACKAGE_STATUS, "development") == 0) { if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION #ifdef HAVE_GIT_VERSION
@ -268,7 +269,6 @@ _init(const int disable_tls, char *log_level)
} }
chat_log_init(); chat_log_init();
groupchat_log_init(); groupchat_log_init();
prefs_load();
accounts_load(); accounts_load();
gchar *theme = prefs_get_string(PREF_THEME); gchar *theme = prefs_get_string(PREF_THEME);
theme_init(theme); theme_init(theme);

View File

@ -1223,6 +1223,10 @@ static void
_cons_log_setting(void) _cons_log_setting(void)
{ {
cons_show("Max log size (/log maxsize) : %d bytes", prefs_get_max_log_size()); 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 static void