mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Merge pull request #16 from ailin-nemui/log-server-time
add a log_server_time setting
This commit is contained in:
commit
e88f476115
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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", "");
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "module.h"
|
||||
#include <irssi/src/core/expandos.h>
|
||||
#include <irssi/src/core/levels.h>
|
||||
#include <irssi/src/core/misc.h>
|
||||
#include <irssi/src/core/refstrings.h>
|
||||
#include <irssi/src/core/servers.h>
|
||||
#include <irssi/src/core/settings.h>
|
||||
@ -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) {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user