From: Christof Schmitt Date: Fri, 9 Jan 2015 20:29:48 +0000 (-0700) Subject: debug: Move mapping from level to syslog priority to helper function X-Git-Tag: tdb-1.3.5~318 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=364e8768d6ead6ff897d2ba85af5ac14aaa562a0;p=thirdparty%2Fsamba.git debug: Move mapping from level to syslog priority to helper function Signed-off-by: Christof Schmitt Reviewed-by: Amitay Isaacs --- diff --git a/lib/util/debug.c b/lib/util/debug.c index e3725a953a1..351a88c5c47 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -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