debug: Move mapping from level to syslog priority to helper function
authorChristof Schmitt <cs@samba.org>
Fri, 9 Jan 2015 20:29:48 +0000 (13:29 -0700)
committerChristof Schmitt <cs@samba.org>
Mon, 23 Mar 2015 20:22:11 +0000 (21:22 +0100)
Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
lib/util/debug.c

index e3725a953a19a15864de249145197f23459548fb..351a88c5c478e12262b6513e468f9977ca062d87 100644 (file)
@@ -102,6 +102,30 @@ static struct {
        .fd = 2 /* stderr by default */
 };
 
+#ifdef WITH_SYSLOG
+static int debug_level_to_priority(int level)
+{
+       /*
+        * map debug levels to syslog() priorities note that not all
+        * DEBUG(0, ...) calls are necessarily errors
+        */
+       static const int priority_map[4] = {
+               LOG_ERR,     /* 0 */
+               LOG_WARNING, /* 1 */
+               LOG_NOTICE,  /* 2 */
+               LOG_INFO,    /* 3 */
+       };
+       int priority;
+
+       if( level >= ARRAY_SIZE(priority_map) || level < 0)
+               priority = LOG_DEBUG;
+       else
+               priority = priority_map[level];
+
+       return priority;
+}
+#endif
+
 /* -------------------------------------------------------------------------- **
  * External variables.
  */
@@ -808,21 +832,7 @@ static int Debug1(const char *msg)
 
 #ifdef WITH_SYSLOG
        if( current_msg_level < state.settings.syslog ) {
-               /* map debug levels to syslog() priorities
-                * note that not all DEBUG(0, ...) calls are
-                * necessarily errors */
-               static const int priority_map[4] = {
-                       LOG_ERR,     /* 0 */
-                       LOG_WARNING, /* 1 */
-                       LOG_NOTICE,  /* 2 */
-                       LOG_INFO,    /* 3 */
-               };
-               int     priority;
-
-               if( current_msg_level >= ARRAY_SIZE(priority_map) || current_msg_level < 0)
-                       priority = LOG_DEBUG;
-               else
-                       priority = priority_map[current_msg_level];
+               int priority = debug_level_to_priority(current_msg_level);
 
                /*
                 * Specify the facility to interoperate with other syslog