[grilo] log: handle numeric level assignations



commit 6c71c336c4299e0dd79ad4258ddd2e3d7cca86c3
Author: Víctor Manuel Jáquez Leal <vjaquez igalia com>
Date:   Wed Sep 1 20:12:49 2010 +0200

    log: handle numeric level assignations
    
    Besides the symbolic level recognition, this patch also enable the numeric
    level setting.
    
    Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez igalia com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=627864

 src/grl-log.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/src/grl-log.c b/src/grl-log.c
index 4c9748b..6d4b84a 100644
--- a/src/grl-log.c
+++ b/src/grl-log.c
@@ -25,6 +25,8 @@
 
 #include <stdarg.h>
 #include <string.h>
+#include <errno.h>
+#include <stdlib.h>
 
 struct _GrlLogDomain {
   /*< private >*/
@@ -166,6 +168,8 @@ static GrlLogLevel
 get_log_level_from_spec (const gchar *level_spec)
 {
   guint i;
+  long int level_num;
+  char *tail;
 
   /* "-" or "none" (from name2level) can be used to disable all logging */
   if (strcmp (level_spec, "-") == 0) {
@@ -177,6 +181,14 @@ get_log_level_from_spec (const gchar *level_spec)
     return GRL_LOG_LEVEL_LAST - 1;
   }
 
+  errno = 0;
+  level_num = strtol (level_spec, &tail, 0);
+  if (!errno
+      && tail != level_spec
+      && level_num >= GRL_LOG_LEVEL_NONE
+      && level_num <= GRL_LOG_LEVEL_LAST - 1)
+      return (GrlLogLevel) level_num;
+
   for (i = 0; i < GRL_LOG_LEVEL_LAST; i++)
     if (strcmp (level_spec, name2level[i]) == 0)
       return i;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]