]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
logging: move check of enabled debugging to DEBUG_LOG macro
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Jun 2014 09:57:56 +0000 (11:57 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Jun 2014 10:12:04 +0000 (12:12 +0200)
This avoids unnecessary calls to the logging function when debugging
messages are not logged. The cost is a slight increase in the size of
the binary (when compiled with debug messages).

logging.c
logging.h

index dff11f16df5af552788ac6c396379f96223472bb..42072ba94dba4e558ad4deff130fd1d93863cb79 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -34,6 +34,9 @@
 #include "mkdirpp.h"
 #include "util.h"
 
+/* This is used by DEBUG_LOG macro */
+int log_debug_enabled = 0;
+
 /* ================================================== */
 /* Flag indicating we have initialised */
 static int initialised = 0;
@@ -148,10 +151,6 @@ void LOG_Message(LOG_Severity severity, LOG_Facility facility,
   time_t t;
   struct tm stm;
 
-  /* Don't write debug messages if debug level is too low */
-  if (debug_level < DEBUG_LEVEL_PRINT_DEBUG && severity == LOGS_DEBUG)
-    return;
-
 #ifdef WINNT
 #else
   if (!system_log) {
@@ -216,8 +215,11 @@ LOG_OpenSystemLog(void)
 void LOG_SetDebugLevel(int level)
 {
   debug_level = level;
-  if (!DEBUG && level >= DEBUG_LEVEL_PRINT_DEBUG)
-    LOG(LOGS_WARN, LOGF_Logging, "Not compiled with full debugging support");
+  if (level >= DEBUG_LEVEL_PRINT_DEBUG) {
+    if (!DEBUG)
+      LOG(LOGS_WARN, LOGF_Logging, "Not compiled with full debugging support");
+    log_debug_enabled = 1;
+  }
 }
 
 /* ================================================== */
index 6f19997b58a26e91b658a04250582540a663518c..70cff5a6e86bcc881a7c8bd11077e76135cea3aa 100644 (file)
--- a/logging.h
+++ b/logging.h
@@ -28,6 +28,9 @@
 #ifndef GOT_LOGGING_H
 #define GOT_LOGGING_H
 
+/* Flag indicating whether debug messages are logged */
+extern int log_debug_enabled;
+
 /* Line logging macros.  If the compiler is GNU C, we take advantage of
    being able to get the function name also. */
 
@@ -41,7 +44,7 @@
 
 #define DEBUG_LOG(facility, ...) \
   do { \
-    if (DEBUG) \
+    if (DEBUG && log_debug_enabled) \
       LOG_Message(LOGS_DEBUG, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__); \
   } while (0)
 #define LOG(severity, facility, ...) LOG_Message(severity, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__)