From 3212469bd8c9e08405665d74064938d398a4bdf1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Jul 2012 21:38:41 +0100 Subject: Added datetime to chat logging --- src/chat_log.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/chat_log.c') diff --git a/src/chat_log.c b/src/chat_log.c index 89681924..78aa99d1 100644 --- a/src/chat_log.c +++ b/src/chat_log.c @@ -29,6 +29,7 @@ #include "common.h" static FILE *chatlog; +static GTimeZone *tz; void chat_log_init(void) { @@ -38,15 +39,23 @@ void chat_log_init(void) g_string_append(log_file, "/chat.log"); chatlog = fopen(log_file->str, "a"); g_string_free(log_file, TRUE); + + tz = g_time_zone_new_local(); } void chat_log_chat(const char * const user, const char * const msg) { - fprintf(chatlog, "%s: %s\n", user, msg); + GDateTime *dt = g_date_time_new_now(tz); + gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S"); + + fprintf(chatlog, "%s: %s: %s\n", date_fmt, user, msg); fflush(chatlog); + + g_date_time_unref(dt); } void chat_log_close(void) { fclose(chatlog); + g_time_zone_unref(tz); } -- cgit 1.4.1-2-gfad0