about summary refs log tree commit diff stats
path: root/src/chat_log.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-07-22 21:38:41 +0100
committerJames Booth <boothj5@gmail.com>2012-07-22 21:38:41 +0100
commit3212469bd8c9e08405665d74064938d398a4bdf1 (patch)
treea1ee5d3b36fd7e2ba97ceec803c09d03152e6aac /src/chat_log.c
parent8e02720a69ab38977ab35cd0768bd04e5d97909c (diff)
downloadprofani-tty-3212469bd8c9e08405665d74064938d398a4bdf1.tar.gz
Added datetime to chat logging
Diffstat (limited to 'src/chat_log.c')
-rw-r--r--src/chat_log.c11
1 files changed, 10 insertions, 1 deletions
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);
 }