]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blobdiff - src/log.c
Rename DEBUG log level to DEBUG1.
[tlsproxy/tlsproxy.git] / src / log.c
index dd7c90cac69e681ac8b4cf656198766c2cc0091d..4dc53f78124b08c621abd33f8123b31fa7e77309 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1,7 +1,7 @@
 /*
  * Log related functions/defines.
  *
- * Copyright (C) 2011  Simon Ruderich
+ * Copyright (C) 2011-2013  Simon Ruderich
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include "tlsproxy.h"
 #include "log.h"
 
-/* va_*() */
-#include <stdarg.h>
-/* pthread_*() */
 #include <pthread.h>
+#include <stdarg.h>
 
 
-void log_message(int level, const char *format, ...) {
+void log_message(int level, const char *file, int line, const char *format, ...) {
     va_list ap;
     const char *level_string;
 
@@ -35,15 +33,34 @@ void log_message(int level, const char *format, ...) {
     }
 
     switch (level) {
-        case LOG_ERROR:   level_string = "ERROR"; break;
-        case LOG_WARNING: level_string = "WARN "; break;
-        case LOG_DEBUG  level_string = "DEBUG"; break;
-        default:          level_string = "UNKNOWN";
+        case LOG_ERROR_LEVEL:   level_string = "ERROR"; break;
+        case LOG_WARNING_LEVEL: level_string = "WARN "; break;
+        case LOG_DEBUG1_LEVEL:  level_string = "DEBUG"; break;
+        default:                level_string = "UNKNOWN";
     }
 
+#ifndef DEBUG
+    /* Prevent warnings. */
+    (void)file;
+    (void)line;
+#endif
+
+    /* Prevent another thread from interrupting the two printfs(). */
+    flockfile(stderr);
+
+    fprintf(stderr,
+#ifdef DEBUG
+            "%-12s:%-3d "
+#endif
+            "[%s] [%d] ",
+#ifdef DEBUG
+            file, line,
+#endif
+            level_string, (int)pthread_self());
     va_start(ap, format);
-    fprintf(stdout, "[%s] [%d] ", level_string, (int)pthread_self());
-    vfprintf(stdout, format, ap);
-    fprintf(stdout, "\n");
+    vfprintf(stderr, format, ap);
     va_end(ap);
+    fprintf(stderr, "\n");
+
+    funlockfile(stderr);
 }