ctdb-logging: Allow numeric specification of debug level
authorAmitay Isaacs <amitay@gmail.com>
Wed, 11 Nov 2015 22:15:08 +0000 (09:15 +1100)
committerMartin Schwenke <martins@samba.org>
Sun, 15 Nov 2015 23:46:14 +0000 (00:46 +0100)
This makes the function compatible with parse_debug().

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/common/logging.c

index cc8e5b2c04bc1456f17de908d65d7133264cb98c..f2304715c8d7776ef3728a010bfd956dd87a8605 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include <replace.h>
+#include <system/locale.h>
 
 #include "common/logging.h"
 
@@ -36,6 +37,16 @@ bool debug_level_parse(const char *log_string, enum debug_level *log_level)
 {
        int i;
 
+       if (isdigit(log_string[0])) {
+               int level = atoi(log_string);
+
+               if (level >= 0 && level < ARRAY_SIZE(log_string_map)) {
+                       *log_level = debug_level_from_int(level);
+                       return true;
+               }
+               return false;
+       }
+
        for (i=0; i<ARRAY_SIZE(log_string_map); i++) {
                if (strncasecmp(log_string_map[i].log_string,
                                log_string, strlen(log_string)) == 0) {