From fdd61f5898c8a97b6a1088db717c16691d601d60 Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Fri, 13 Aug 2021 21:11:22 +0200 Subject: [PATCH 1/3] add a log_server_time setting --- src/core/log.c | 14 +++++++------- src/core/log.h | 6 +++--- src/fe-common/core/fe-log.c | 33 ++++++++++++++++++++++++++------- src/perl/common/Log.xs | 3 ++- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index cb6f1edd..5bc953a1 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -204,11 +204,10 @@ static void log_rotate_check(LOG_REC *log) g_free(new_fname); } -void log_write_rec(LOG_REC *log, const char *str, int level) +void log_write_rec(LOG_REC *log, const char *str, int level, time_t now) { char *colorstr; struct tm *tm; - time_t now; int hour, day; g_return_if_fail(log != NULL); @@ -217,7 +216,8 @@ void log_write_rec(LOG_REC *log, const char *str, int level) if (log->handle == -1) return; - now = time(NULL); + if (now == (time_t) -1) + now = time(NULL); tm = localtime(&now); hour = tm->tm_hour; day = tm->tm_mday; @@ -282,8 +282,8 @@ LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item, return NULL; } -void log_file_write(const char *server_tag, const char *item, int level, - const char *str, int no_fallbacks) +void log_file_write(const char *server_tag, const char *item, int level, time_t t, const char *str, + int no_fallbacks) { GSList *tmp, *fallbacks; char *tmpstr; @@ -309,7 +309,7 @@ void log_file_write(const char *server_tag, const char *item, int level, fallbacks = g_slist_append(fallbacks, rec); else if (log_item_find(rec, LOG_ITEM_TARGET, item, server_tag) != NULL) - log_write_rec(rec, str, level); + log_write_rec(rec, str, level, t); } if (!found && !no_fallbacks && fallbacks != NULL) { @@ -319,7 +319,7 @@ void log_file_write(const char *server_tag, const char *item, int level, g_strdup(str); for (tmp = fallbacks; tmp != NULL; tmp = tmp->next) - log_write_rec(tmp->data, tmpstr, level); + log_write_rec(tmp->data, tmpstr, level, t); g_free(tmpstr); } diff --git a/src/core/log.h b/src/core/log.h index 1c529670..19bca4f3 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -51,9 +51,9 @@ void log_item_destroy(LOG_REC *log, LOG_ITEM_REC *item); LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item, const char *servertag); -void log_file_write(const char *server_tag, const char *item, int level, - const char *str, int no_fallbacks); -void log_write_rec(LOG_REC *log, const char *str, int level); +void log_file_write(const char *server_tag, const char *item, int level, time_t t, const char *str, + int no_fallbacks); +void log_write_rec(LOG_REC *log, const char *str, int level, time_t now); int log_start_logging(LOG_REC *log); void log_stop_logging(LOG_REC *log); diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index b5222059..984b3548 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -48,6 +48,7 @@ #define AUTOLOG_INACTIVITY_CLOSE (60*5) static int autolog_level; +static int log_server_time; static int autoremove_tag; static char *autolog_path; @@ -502,8 +503,8 @@ static void autolog_open_check(TEXT_DEST_REC *dest) autolog_open(server, server_tag, g_strcmp0(target, "*") ? target : deftarget); } -static void log_single_line(WINDOW_REC *window, const char *server_tag, - const char *target, int level, const char *text) +static void log_single_line(WINDOW_REC *window, const char *server_tag, const char *target, + int level, time_t t, const char *text) { char windownum[MAX_INT_STRLEN]; LOG_REC *log; @@ -514,15 +515,16 @@ static void log_single_line(WINDOW_REC *window, const char *server_tag, log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, windownum, NULL, NULL); if (log != NULL) - log_write_rec(log, text, level); + log_write_rec(log, text, level, t); } - log_file_write(server_tag, target, level, text, FALSE); + log_file_write(server_tag, target, level, t, text, FALSE); } static void log_line(TEXT_DEST_REC *dest, const char *text) { char **lines, **tmp; + time_t t = (time_t) -1; if (dest->level == MSGLEVEL_NEVER) return; @@ -536,9 +538,18 @@ static void log_line(TEXT_DEST_REC *dest, const char *text) /* text may contain one or more lines, log wants to eat them one line at a time */ lines = g_strsplit(text, "\n", -1); + if (log_server_time && dest->meta != NULL) { + char *val; + if ((val = g_hash_table_lookup(dest->meta, "time")) != NULL) { + GDateTime *time; + if ((time = g_date_time_new_from_iso8601(val, NULL)) != NULL) { + t = g_date_time_to_unix(time); + g_date_time_unref(time); + } + } + } for (tmp = lines; *tmp != NULL; tmp++) - log_single_line(dest->window, dest->server_tag, - dest->target, dest->level, *tmp); + log_single_line(dest->window, dest->server_tag, dest->target, dest->level, t, *tmp); g_strfreev(lines); } @@ -720,6 +731,13 @@ static void read_settings(void) g_strfreev(autolog_ignore_targets); autolog_ignore_targets = g_strsplit(settings_get_str("autolog_ignore_targets"), " ", -1); + + log_server_time = settings_get_choice("log_server_time"); + if (log_server_time == 2) { + SETTINGS_REC *rec = settings_get_record("show_server_time"); + if (rec != NULL) + log_server_time = settings_get_bool("show_server_time"); + } } void fe_log_init(void) @@ -731,7 +749,8 @@ void fe_log_init(void) settings_add_bool("log", "autolog", FALSE); settings_add_bool("log", "autolog_colors", FALSE); settings_add_bool("log", "autolog_only_saved_channels", FALSE); - settings_add_str("log", "autolog_path", "~/irclogs/$tag/$0.log"); + settings_add_choice("log", "log_server_time", 2, "off;on;auto"); + settings_add_str("log", "autolog_path", "~/irclogs/$tag/$0.log"); settings_add_level("log", "autolog_level", "all -crap -clientcrap -ctcps"); settings_add_str("log", "log_theme", ""); settings_add_str("log", "autolog_ignore_targets", ""); diff --git a/src/perl/common/Log.xs b/src/perl/common/Log.xs index cdcdbd90..532095fb 100644 --- a/src/perl/common/Log.xs +++ b/src/perl/common/Log.xs @@ -54,10 +54,11 @@ log_close(log) Irssi::Log log void -log_write_rec(log, str, level) +log_write_rec(log, str, level, now = -1) Irssi::Log log char *str int level + time_t now void log_start_logging(log) From 6a331399399dc9b91d75fbe6b065e31a2db49fe0 Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Sat, 14 Aug 2021 22:43:50 +0200 Subject: [PATCH 2/3] compat for glib 2.55 --- src/core/misc.c | 20 ++++++++++++++++---- src/core/misc.h | 7 +++++++ src/fe-text/textbuffer-formats.c | 16 +--------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index c66bbd6d..f0bbf4e0 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -95,7 +95,6 @@ int i_input_add_poll(int fd, int priority, int condition, GInputFunction functio #pragma GCC diagnostic ignored "-Wdeprecated-declarations" int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2) { -#pragma GCC diagnostic pop if (tv1->tv_sec < tv2->tv_sec) return -1; if (tv1->tv_sec > tv2->tv_sec) @@ -105,11 +104,8 @@ int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2) tv1->tv_usec > tv2->tv_usec ? 1 : 0; } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2) { -#pragma GCC diagnostic pop long secs, usecs; secs = tv1->tv_sec - tv2->tv_sec; @@ -122,6 +118,22 @@ long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2) return usecs; } +#pragma GCC diagnostic pop + +#if GLIB_CHECK_VERSION(2, 56, 0) +/* nothing */ +#else +/* compatibility code for old GLib */ +GDateTime *g_date_time_new_from_iso8601(const gchar *iso_date, GTimeZone *default_tz) +{ + GTimeVal time; + if (g_time_val_from_iso8601(iso_date, &time)) { + return g_date_time_new_from_timeval_utc(&time); + } else { + return NULL; + } +} +#endif int find_substr(const char *list, const char *item) { diff --git a/src/core/misc.h b/src/core/misc.h index 76f5644b..622470f7 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -19,6 +19,13 @@ int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2) G_GNUC_DEPRECATED; long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2) G_GNUC_DEPRECATED; #pragma GCC diagnostic pop +#if GLIB_CHECK_VERSION(2, 56, 0) +/* nothing */ +#else +/* compatibility code for old GLib */ +GDateTime *g_date_time_new_from_iso8601(const gchar *iso_date, GTimeZone *default_tz); +#endif + GSList *i_slist_find_string(GSList *list, const char *key); GSList *i_slist_find_icase_string(GSList *list, const char *key); GList *i_list_find_string(GList *list, const char *key); diff --git a/src/fe-text/textbuffer-formats.c b/src/fe-text/textbuffer-formats.c index 5b15313f..20abc0df 100644 --- a/src/fe-text/textbuffer-formats.c +++ b/src/fe-text/textbuffer-formats.c @@ -1,6 +1,7 @@ #include "module.h" #include #include +#include #include #include #include @@ -18,21 +19,6 @@ gboolean scrollback_format; gboolean show_server_time; int signal_gui_render_line_text; -#if GLIB_CHECK_VERSION(2, 56, 0) -/* nothing */ -#else -/* compatibility code for old GLib */ -static GDateTime *g_date_time_new_from_iso8601(const gchar *iso_date, GTimeZone *default_tz) -{ - GTimeVal time; - if (g_time_val_from_iso8601(iso_date, &time)) { - return g_date_time_new_from_timeval_utc(&time); - } else { - return NULL; - } -} -#endif - static void collector_free(GSList **collector) { while (*collector) { From b3f74fe0ab1fd8dc145dab662e74eeaaeeb6fffe Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Sun, 15 Aug 2021 15:58:10 +0200 Subject: [PATCH 3/3] up abi --- src/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index cc334476..a89b4964 100644 --- a/src/common.h +++ b/src/common.h @@ -6,7 +6,7 @@ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ -#define IRSSI_ABI_VERSION 38 +#define IRSSI_ABI_VERSION 39 #define DEFAULT_SERVER_ADD_PORT 6667 #define DEFAULT_SERVER_ADD_TLS_PORT 6697