about summary refs log tree commit diff stats
path: root/src/log.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-08-19 02:44:46 +0100
committerJames Booth <boothj5@gmail.com>2012-08-19 02:44:46 +0100
commit74a88ad566989ef91641d0e8b95120bc6a66accd (patch)
tree5ac6340caec7a99cdde9853b35d374854f685162 /src/log.c
parent108194c944b49153ce012fb6b88ed6833886435c (diff)
downloadprofani-tty-74a88ad566989ef91641d0e8b95120bc6a66accd.tar.gz
Basic log levels settings
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/log.c b/src/log.c
index 2952fcaa..cbaf7eb7 100644
--- a/src/log.c
+++ b/src/log.c
@@ -32,19 +32,23 @@ static FILE *logp;
 
 static GTimeZone *tz;
 static GDateTime *dt;
+static log_level_t prof_log_level;
 
 void
-log_msg(const char * const area, const char * const msg)
+log_msg(log_level_t level, const char * const area, const char * const msg)
 {
-    dt = g_date_time_new_now(tz);                                      
-    gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S");               
-    fprintf(logp, "%s: %s DEBUG: %s\n", date_fmt, area, msg);
-    g_date_time_unref(dt);
+    if (level >= prof_log_level) {
+        dt = g_date_time_new_now(tz);                                      
+        gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S");               
+        fprintf(logp, "%s: %s: %s\n", date_fmt, area, msg);
+        g_date_time_unref(dt);
+    }
 }
 
 void
-log_init(void)
+log_init(log_level_t log_level)
 {
+    prof_log_level = log_level;
     tz = g_time_zone_new_local();
     GString *log_file = g_string_new(getenv("HOME"));
     g_string_append(log_file, "/.profanity/log");
@@ -52,7 +56,13 @@ log_init(void)
     g_string_append(log_file, "/profanity.log");
     logp = fopen(log_file->str, "a");
     g_string_free(log_file, TRUE);
-    log_msg(PROF, "Starting Profanity...");
+    log_msg(PROF_LEVEL_INFO, PROF, "Starting Profanity...");
+}
+
+log_level_t
+log_get_level(void)
+{
+    return prof_log_level;
 }
 
 void