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:
parent
bc6f8ceb3a
commit
a4a23fdf68
@ -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,
|
||||
@ -1674,6 +1677,24 @@ _autoaway_autocomplete(char *input, int *size)
|
||||
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 *
|
||||
_autoconnect_autocomplete(char *input, int *size)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user