1
0
mirror of https://github.com/irssi/irssi.git synced 2024-06-30 06:45:25 +00:00

Merge pull request #1432 from horgh/horgh/win-logfile

Check window logfile parameter
This commit is contained in:
ailin-nemui 2022-12-23 10:34:56 +01:00 committed by GitHub
commit 6f5026fd49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,10 +92,10 @@ static void cmd_log_open(const char *data)
LOG_REC *log; LOG_REC *log;
int level; int level;
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | if (!cmd_get_params(data, &free_arg,
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_OPTIONS | 2 | PARAM_FLAG_GETREST | PARAM_FLAG_UNKNOWN_OPTIONS |
PARAM_FLAG_STRIP_TRAILING_WS, "log open", &optlist, PARAM_FLAG_OPTIONS | PARAM_FLAG_STRIP_TRAILING_WS,
&fname, &levels)) "log open", &optlist, &fname, &levels))
return; return;
if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
@ -113,8 +113,7 @@ static void cmd_log_open(const char *data)
ltoa(window, active_win->refnum); ltoa(window, active_win->refnum);
targetarg = window; targetarg = window;
} }
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, targetarg, log_item_add(log, LOG_ITEM_WINDOW_REFNUM, targetarg, servertag);
servertag);
} else { } else {
targetarg = g_hash_table_lookup(optlist, "targets"); targetarg = g_hash_table_lookup(optlist, "targets");
if (targetarg != NULL && *targetarg != '\0') if (targetarg != NULL && *targetarg != '\0')
@ -134,8 +133,7 @@ static void cmd_log_open(const char *data)
if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) { if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) {
/* start logging */ /* start logging */
if (log_start_logging(log)) { if (log_start_logging(log)) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_LOG_OPENED, fname);
TXT_LOG_OPENED, fname);
} else { } else {
log_close(log); log_close(log);
} }
@ -232,12 +230,10 @@ static void cmd_log_list(void)
LOG_REC *rec = tmp->data; LOG_REC *rec = tmp->data;
levelstr = bits2level(rec->level); levelstr = bits2level(rec->level);
items = rec->items == NULL ? NULL : items = rec->items == NULL ? NULL : log_items_get_list(rec);
log_items_get_list(rec);
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_LOG_LIST, printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_LOG_LIST, index, rec->fname,
index, rec->fname, items != NULL ? items : "", items != NULL ? items : "", levelstr, rec->autoopen ? " -autoopen" : "",
levelstr, rec->autoopen ? " -autoopen" : "",
rec->handle != -1 ? " active" : ""); rec->handle != -1 ? " active" : "");
g_free_not_null(items); g_free_not_null(items);
@ -254,8 +250,8 @@ static void cmd_log(const char *data, SERVER_REC *server, void *item)
command_runsub("log", data, server, item); command_runsub("log", data, server, item);
} }
static LOG_REC *logs_find_item(int type, const char *item, static LOG_REC *logs_find_item(int type, const char *item, const char *servertag,
const char *servertag, LOG_ITEM_REC **ret_item) LOG_ITEM_REC **ret_item)
{ {
LOG_ITEM_REC *logitem; LOG_ITEM_REC *logitem;
GSList *tmp; GSList *tmp;
@ -332,21 +328,34 @@ static void cmd_window_logfile(const char *data)
{ {
LOG_REC *log; LOG_REC *log;
char window[MAX_INT_STRLEN]; char window[MAX_INT_STRLEN];
void *free_arg;
char *fname;
if (!cmd_get_params(data, &free_arg, 1, &fname)) {
return;
}
if (!fname || strlen(fname) == 0) {
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
}
ltoa(window, active_win->refnum); ltoa(window, active_win->refnum);
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, window, NULL, NULL); log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, window, NULL, NULL);
if (log != NULL) { if (log != NULL) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOWLOG_FILE_LOGGING); printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOWLOG_FILE_LOGGING);
cmd_params_free(free_arg);
return; return;
} }
log = log_create_rec(data, MSGLEVEL_ALL); log = log_create_rec(fname, MSGLEVEL_ALL);
log->colorizer = log_colorizer_strip; log->colorizer = log_colorizer_strip;
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL); log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL);
log_update(log); log_update(log);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOWLOG_FILE, data); printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOWLOG_FILE, data);
cmd_params_free(free_arg);
} }
/* window's refnum changed - update the logs to log the new window refnum */ /* window's refnum changed - update the logs to log the new window refnum */
@ -380,10 +389,10 @@ static void sig_server_disconnected(SERVER_REC *server)
continue; continue;
logitem = log->items->data; logitem = log->items->data;
if (logitem->type == LOG_ITEM_TARGET && if (logitem->type == LOG_ITEM_TARGET && logitem->servertag != NULL &&
logitem->servertag != NULL &&
g_ascii_strcasecmp(logitem->servertag, server->tag) == 0 && g_ascii_strcasecmp(logitem->servertag, server->tag) == 0 &&
server_ischannel(server, logitem->name)) /* kludge again.. so we won't close dcc chats */ server_ischannel(
server, logitem->name)) /* kludge again.. so we won't close dcc chats */
log_close(log); log_close(log);
} }
} }
@ -422,8 +431,7 @@ static char *escape_target(const char *target)
return str; return str;
} }
static void autolog_open(SERVER_REC *server, const char *server_tag, static void autolog_open(SERVER_REC *server, const char *server_tag, const char *target)
const char *target)
{ {
LOG_REC *log; LOG_REC *log;
char *fname, *dir, *fixed_target, *params; char *fname, *dir, *fixed_target, *params;
@ -448,8 +456,7 @@ static void autolog_open(SERVER_REC *server, const char *server_tag,
params = g_strconcat(fixed_target, " ", server_tag, NULL); params = g_strconcat(fixed_target, " ", server_tag, NULL);
g_free(fixed_target); g_free(fixed_target);
fname = parse_special_string(autolog_path, server, NULL, fname = parse_special_string(autolog_path, server, NULL, params, NULL, 0);
params, NULL, 0);
g_free(params); g_free(params);
if (log_find(fname) == NULL) { if (log_find(fname) == NULL) {
@ -485,8 +492,8 @@ static void autolog_open_check(TEXT_DEST_REC *dest)
we're parting the channel with /WINDOW CLOSE.. Maybe a small we're parting the channel with /WINDOW CLOSE.. Maybe a small
timeout would be nice instead of immediately closing the log file timeout would be nice instead of immediately closing the log file
after "window item destroyed" */ after "window item destroyed" */
if (level == MSGLEVEL_PARTS || if (level == MSGLEVEL_PARTS || (autolog_level & level) == 0 || target == NULL ||
(autolog_level & level) == 0 || target == NULL || *target == '\0') *target == '\0')
return; return;
deftarget = server ? server->nick : "unknown"; deftarget = server ? server->nick : "unknown";
@ -496,8 +503,7 @@ static void autolog_open_check(TEXT_DEST_REC *dest)
&& channel_setup_find(target, server_tag) == NULL) && channel_setup_find(target, server_tag) == NULL)
return; return;
if (autolog_ignore_targets != NULL && if (autolog_ignore_targets != NULL && strarray_find_dest(autolog_ignore_targets, dest))
strarray_find_dest(autolog_ignore_targets, dest))
return; return;
if (target != NULL) if (target != NULL)
@ -513,8 +519,7 @@ static void log_single_line(WINDOW_REC *window, const char *server_tag, const ch
if (window != NULL) { if (window != NULL) {
/* save to log created with /WINDOW LOG */ /* save to log created with /WINDOW LOG */
ltoa(windownum, window->refnum); ltoa(windownum, window->refnum);
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, windownum, NULL, NULL);
windownum, NULL, NULL);
if (log != NULL) if (log != NULL)
log_write_rec(log, text, level, t); log_write_rec(log, text, level, t);
} }
@ -554,8 +559,7 @@ static void log_line(TEXT_DEST_REC *dest, const char *text)
g_strfreev(lines); g_strfreev(lines);
} }
static void sig_printtext(TEXT_DEST_REC *dest, const char *text, static void sig_printtext(TEXT_DEST_REC *dest, const char *text, const char *stripped)
const char *stripped)
{ {
if (skip_next_printtext) { if (skip_next_printtext) {
skip_next_printtext = FALSE; skip_next_printtext = FALSE;
@ -565,8 +569,8 @@ static void sig_printtext(TEXT_DEST_REC *dest, const char *text,
log_line(dest, text); log_line(dest, text);
} }
static void sig_print_format(THEME_REC *theme, const char *module, static void sig_print_format(THEME_REC *theme, const char *module, TEXT_DEST_REC *dest,
TEXT_DEST_REC *dest, void *formatnum, char **args) void *formatnum, char **args)
{ {
char *str, *linestart, *tmp; char *str, *linestart, *tmp;
@ -580,8 +584,8 @@ static void sig_print_format(THEME_REC *theme, const char *module,
if (theme == log_theme) if (theme == log_theme)
return; return;
str = format_get_text_theme_charargs(log_theme, module, dest, str = format_get_text_theme_charargs(log_theme, module, dest, GPOINTER_TO_INT(formatnum),
GPOINTER_TO_INT(formatnum), args); args);
if (str != NULL && *str != '\0') { if (str != NULL && *str != '\0') {
skip_next_printtext = TRUE; skip_next_printtext = TRUE;
@ -606,7 +610,7 @@ static int sig_autoremove(void)
GSList *tmp, *next; GSList *tmp, *next;
time_t removetime; time_t removetime;
removetime = time(NULL)-AUTOLOG_INACTIVITY_CLOSE; removetime = time(NULL) - AUTOLOG_INACTIVITY_CLOSE;
for (tmp = logs; tmp != NULL; tmp = next) { for (tmp = logs; tmp != NULL; tmp = next) {
LOG_REC *log = tmp->data; LOG_REC *log = tmp->data;
@ -621,8 +625,8 @@ static int sig_autoremove(void)
continue; continue;
server = server_find_tag(logitem->servertag); server = server_find_tag(logitem->servertag);
if (logitem->type == LOG_ITEM_TARGET && if (logitem->type == LOG_ITEM_TARGET && server != NULL &&
server != NULL && !server_ischannel(server, logitem->name)) !server_ischannel(server, logitem->name))
log_close(log); log_close(log);
} }
return 1; return 1;
@ -633,23 +637,20 @@ static void sig_window_item_remove(WINDOW_REC *window, WI_ITEM_REC *item)
LOG_REC *log; LOG_REC *log;
log = logs_find_item(LOG_ITEM_TARGET, item->visible_name, log = logs_find_item(LOG_ITEM_TARGET, item->visible_name,
item->server == NULL ? NULL : item->server == NULL ? NULL : item->server->tag, NULL);
item->server->tag, NULL);
if (log != NULL && log->temp) if (log != NULL && log->temp)
log_close(log); log_close(log);
} }
static void sig_log_locked(LOG_REC *log) static void sig_log_locked(LOG_REC *log)
{ {
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_LOG_LOCKED, log->real_fname);
TXT_LOG_LOCKED, log->real_fname);
} }
static void sig_log_create_failed(LOG_REC *log) static void sig_log_create_failed(LOG_REC *log)
{ {
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_LOG_CREATE_FAILED, log->real_fname,
TXT_LOG_CREATE_FAILED, g_strerror(errno));
log->real_fname, g_strerror(errno));
} }
static void sig_log_new(LOG_REC *log) static void sig_log_new(LOG_REC *log)