1
0
Fork 0

Added /log shared setting

Issue #170
This commit is contained in:
James Booth 2014-04-13 21:56:35 +01:00
parent a4a23fdf68
commit c3418a2909
8 changed files with 52 additions and 8 deletions

View File

@ -644,8 +644,9 @@ static struct cmd_t command_defs[] =
{ "/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)",
"rotate : Rotate log, accepts 'on' or 'off', defaults to 'on'.",
"maxsize : With rotate enabled, specifies the max log size, defaults to 1048580 (1MB).",
"shared : Share logs between all instances, accepts 'on' or 'off', defaults to 'on'.",
NULL } } },
{ "/reconnect",
@ -953,6 +954,7 @@ cmd_init(void)
log_ac = autocomplete_new();
autocomplete_add(log_ac, "maxsize");
autocomplete_add(log_ac, "rotate");
autocomplete_add(log_ac, "shared");
autoaway_ac = autocomplete_new();
autocomplete_add(autoaway_ac, "mode");
@ -1687,6 +1689,11 @@ _log_autocomplete(char *input, int *size)
if (result != NULL) {
return result;
}
result = autocomplete_param_with_func(input, size, "/log shared",
prefs_autocomplete_boolean_choice);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/log", log_ac);
if (result != NULL) {
return result;

View File

@ -2304,6 +2304,18 @@ cmd_log(gchar **args, struct cmd_help_t help)
}
}
if (strcmp(subcmd, "shared") == 0) {
if (value == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
gboolean result = _cmd_set_boolean_preference(value, help,
"Shared log", PREF_LOG_SHARED);
log_reinit();
return result;
}
}
cons_show("Usage: %s", help.usage);
/* TODO: make 'level' subcommand for debug level */

View File

@ -394,6 +394,7 @@ _get_group(preference_t pref)
case PREF_GRLOG:
case PREF_OTR_LOG:
case PREF_LOG_ROTATE:
case PREF_LOG_SHARED:
return PREF_GROUP_LOGGING;
case PREF_AUTOAWAY_CHECK:
case PREF_AUTOAWAY_MODE:
@ -467,6 +468,8 @@ _get_key(preference_t pref)
return "otr.warn";
case PREF_LOG_ROTATE:
return "rotate";
case PREF_LOG_SHARED:
return "shared";
default:
return NULL;
}
@ -481,6 +484,7 @@ _get_default_boolean(preference_t pref)
case PREF_OTR_WARN:
case PREF_AUTOAWAY_CHECK:
case PREF_LOG_ROTATE:
case PREF_LOG_SHARED:
return TRUE;
default:
return FALSE;

View File

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

View File

@ -25,6 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "glib.h"
@ -60,7 +61,7 @@ static char * _get_log_filename(const char * const other, const char * const log
static char * _get_groupchat_log_filename(const char * const room,
const char * const login, GDateTime *dt, gboolean create);
static gchar * _get_chatlog_dir(void);
static gchar * _get_log_file(void);
static gchar * _get_main_log_file(void);
static void _rotate_log_file(void);
static char* _log_string_from_level(log_level_t level);
@ -117,11 +118,18 @@ log_init(log_level_t filter)
{
level_filter = filter;
tz = g_time_zone_new_local();
gchar *log_file = _get_log_file();
gchar *log_file = _get_main_log_file();
logp = fopen(log_file, "a");
free(log_file);
}
void
log_reinit(void)
{
log_close();
log_init(level_filter);
}
log_level_t
log_get_filter(void)
{
@ -183,7 +191,7 @@ log_level_from_string(char *log_level)
static void
_rotate_log_file(void)
{
gchar *log_file = _get_log_file();
gchar *log_file = _get_main_log_file();
size_t len = strlen(log_file);
char *log_file_new = malloc(len + 3);
@ -518,11 +526,15 @@ _get_chatlog_dir(void)
}
static gchar *
_get_log_file(void)
_get_main_log_file(void)
{
gchar *xdg_data = xdg_get_data_home();
GString *logfile = g_string_new(xdg_data);
g_string_append(logfile, "/profanity/logs/profanity.log");
g_string_append(logfile, "/profanity/logs/profanity");
if (!prefs_get_boolean(PREF_LOG_SHARED)) {
g_string_append_printf(logfile, "%d", getpid());
}
g_string_append(logfile, ".log");
gchar *result = strdup(logfile->str);
free(xdg_data);
g_string_free(logfile, TRUE);

View File

@ -41,6 +41,7 @@ typedef enum {
void log_init(log_level_t filter);
log_level_t log_get_filter(void);
void log_close(void);
void log_reinit(void);
void log_debug(const char * const msg, ...);
void log_info(const char * const msg, ...);
void log_warning(const char * const msg, ...);

View File

@ -1223,10 +1223,16 @@ 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");
if (prefs_get_boolean(PREF_LOG_SHARED))
cons_show("Shared log (/log shared) : ON");
else
cons_show("Shared log (/log shared) : OFF");
}
static void

View File

@ -31,6 +31,7 @@ log_level_t log_get_filter(void)
{
return (log_level_t)mock();
}
void log_reinit(void) {}
void log_close(void) {}
void log_debug(const char * const msg, ...) {}
void log_info(const char * const msg, ...) {}