mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
complete log rotation support
add command '/log maxsize <int>' save maxsize value to config file when maxsize < 64 default value 1MB is used
This commit is contained in:
parent
2234979031
commit
e559c33df4
@ -72,6 +72,8 @@ static char *_cmd_notify_complete(char *inp);
|
||||
static void _cmd_notify_reset_completer(void);
|
||||
static char *_cmd_sub_complete(char *inp);
|
||||
static void _cmd_sub_reset_completer(void);
|
||||
static char *_cmd_log_complete(char *inp);
|
||||
static void _cmd_log_reset_completer(void);
|
||||
static void _cmd_complete_parameters(char *input, int *size);
|
||||
static void _notify_autocomplete(char *input, int *size);
|
||||
static void _parameter_autocomplete(char *input, int *size, char *command,
|
||||
@ -92,6 +94,7 @@ static gboolean _cmd_close(const char * const inp, struct cmd_help_t help);
|
||||
static gboolean _cmd_join(const char * const inp, struct cmd_help_t help);
|
||||
static gboolean _cmd_set_beep(const char * const inp, struct cmd_help_t help);
|
||||
static gboolean _cmd_set_notify(const char * const inp, struct cmd_help_t help);
|
||||
static gboolean _cmd_set_log(const char * const inp, struct cmd_help_t help);
|
||||
static gboolean _cmd_set_intype(const char * const inp, struct cmd_help_t help);
|
||||
static gboolean _cmd_set_flash(const char * const inp, struct cmd_help_t help);
|
||||
static gboolean _cmd_set_showsplash(const char * const inp, struct cmd_help_t help);
|
||||
@ -408,6 +411,18 @@ static struct cmd_t setting_commands[] =
|
||||
"",
|
||||
"Config file section : [ui]",
|
||||
"Config file value : history=true|false",
|
||||
NULL } } },
|
||||
|
||||
{ "/log",
|
||||
_cmd_set_log,
|
||||
{ "/log maxsize <value>", "Manage system logging settings.",
|
||||
{ "/history maxsize <value>",
|
||||
"---------------",
|
||||
"maxsize : When log file size exceeds this value it will be automatically",
|
||||
" rotated (file will be renamed). Default value is 1048580 (1MB)",
|
||||
"",
|
||||
"Config file section : [log]",
|
||||
"Config file value : maxsize=bytes",
|
||||
NULL } } }
|
||||
};
|
||||
|
||||
@ -477,6 +492,7 @@ static PAutocomplete who_ac;
|
||||
static PAutocomplete help_ac;
|
||||
static PAutocomplete notify_ac;
|
||||
static PAutocomplete sub_ac;
|
||||
static PAutocomplete log_ac;
|
||||
|
||||
/*
|
||||
* Initialise command autocompleter and history
|
||||
@ -507,6 +523,9 @@ cmd_init(void)
|
||||
p_autocomplete_add(sub_ac, strdup("req"));
|
||||
p_autocomplete_add(sub_ac, strdup("show"));
|
||||
|
||||
log_ac = p_autocomplete_new();
|
||||
p_autocomplete_add(log_ac, strdup("maxsize"));
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < ARRAY_SIZE(main_commands); i++) {
|
||||
struct cmd_t *pcmd = main_commands+i;
|
||||
@ -580,6 +599,7 @@ cmd_reset_autocomplete()
|
||||
_cmd_notify_reset_completer();
|
||||
_cmd_sub_reset_completer();
|
||||
_cmd_who_reset_completer();
|
||||
_cmd_log_reset_completer();
|
||||
_cmd_reset_command_completer();
|
||||
}
|
||||
|
||||
@ -721,6 +741,18 @@ _cmd_sub_reset_completer(void)
|
||||
p_autocomplete_reset(sub_ac);
|
||||
}
|
||||
|
||||
static char *
|
||||
_cmd_log_complete(char *inp)
|
||||
{
|
||||
return p_autocomplete_complete(log_ac, inp);
|
||||
}
|
||||
|
||||
static void
|
||||
_cmd_log_reset_completer(void)
|
||||
{
|
||||
p_autocomplete_reset(log_ac);
|
||||
}
|
||||
|
||||
static void
|
||||
_cmd_complete_parameters(char *input, int *size)
|
||||
{
|
||||
@ -753,6 +785,8 @@ _cmd_complete_parameters(char *input, int *size)
|
||||
_cmd_help_complete);
|
||||
_parameter_autocomplete(input, size, "/who",
|
||||
_cmd_who_complete);
|
||||
_parameter_autocomplete(input, size, "/log",
|
||||
_cmd_log_complete);
|
||||
|
||||
_notify_autocomplete(input, size);
|
||||
}
|
||||
@ -1346,6 +1380,30 @@ _cmd_set_notify(const char * const inp, struct cmd_help_t help)
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cmd_set_log(const char * const inp, struct cmd_help_t help)
|
||||
{
|
||||
char *subcmd, *value;
|
||||
char inp_cpy[strlen(inp) + 1];
|
||||
int intval;
|
||||
|
||||
strcpy(inp_cpy, inp);
|
||||
strtok(inp_cpy, " ");
|
||||
subcmd = strtok(NULL, " ");
|
||||
value = strtok(NULL, " ");
|
||||
if (subcmd == NULL || value == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
} else {
|
||||
if (strcmp(subcmd, "maxsize") == 0) {
|
||||
intval = atoi(value);
|
||||
prefs_set_max_log_size(intval);
|
||||
cons_show("Log maxinum size set to %d bytes", intval);
|
||||
}
|
||||
/* TODO: make 'level' subcommand for debug level */
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cmd_vercheck(const char * const inp, struct cmd_help_t help)
|
||||
{
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
static GString *prefs_loc;
|
||||
static GKeyFile *prefs;
|
||||
gint log_maxsize = 0;
|
||||
|
||||
static PAutocomplete login_ac;
|
||||
static PAutocomplete boolean_choice_ac;
|
||||
@ -87,6 +88,8 @@ static void _save_prefs(void);
|
||||
void
|
||||
prefs_load(void)
|
||||
{
|
||||
GError *err;
|
||||
|
||||
log_info("Loading preferences");
|
||||
login_ac = p_autocomplete_new();
|
||||
prefs_loc = g_string_new(getenv("HOME"));
|
||||
@ -113,6 +116,13 @@ prefs_load(void)
|
||||
|
||||
_load_colours();
|
||||
|
||||
err = NULL;
|
||||
log_maxsize = g_key_file_get_integer(prefs, "log", "maxsize", &err);
|
||||
if (err != NULL) {
|
||||
log_maxsize = 0;
|
||||
g_error_free(err);
|
||||
}
|
||||
|
||||
boolean_choice_ac = p_autocomplete_new();
|
||||
p_autocomplete_add(boolean_choice_ac, strdup("on"));
|
||||
p_autocomplete_add(boolean_choice_ac, strdup("off"));
|
||||
@ -303,8 +313,18 @@ prefs_set_notify_remind(gint value)
|
||||
gint
|
||||
prefs_get_max_log_size(void)
|
||||
{
|
||||
/* TODO: make command and field in config file */
|
||||
return PREFS_MAX_LOG_SIZE;
|
||||
if (log_maxsize < PREFS_MIN_LOG_SIZE)
|
||||
return PREFS_MAX_LOG_SIZE;
|
||||
else
|
||||
return log_maxsize;
|
||||
}
|
||||
|
||||
void
|
||||
prefs_set_max_log_size(gint value)
|
||||
{
|
||||
log_maxsize = value;
|
||||
g_key_file_set_integer(prefs, "log", "maxsize", value);
|
||||
_save_prefs();
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <ncurses/ncurses.h>
|
||||
#endif
|
||||
|
||||
#define PREFS_MIN_LOG_SIZE 64
|
||||
#define PREFS_MAX_LOG_SIZE 1048580
|
||||
|
||||
void prefs_load(void);
|
||||
@ -69,6 +70,7 @@ void prefs_set_notify_typing(gboolean value);
|
||||
gboolean prefs_get_notify_typing(void);
|
||||
void prefs_set_notify_remind(gint period);
|
||||
gint prefs_get_notify_remind(void);
|
||||
void prefs_set_max_log_size(gint value);
|
||||
gint prefs_get_max_log_size(void);
|
||||
|
||||
void prefs_add_login(const char *jid);
|
||||
|
Loading…
Reference in New Issue
Block a user