]> xenbits.xensource.com Git - xen.git/commitdiff
xl: Allow control of logging level.
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 28 May 2010 08:35:12 +0000 (09:35 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 28 May 2010 08:35:12 +0000 (09:35 +0100)
The -v option, which must come before the xl command, increases the
logging level each time it is supplied.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxc/xtl_logger_stdio.c
tools/libxl/xl.c
tools/libxl/xl.h

index 587c67da6ab1ab04a5f5b0c17197e02e576aff87..abe274ab08e44873e0c7d7b4af5dc92bef02efcc 100644 (file)
@@ -36,6 +36,9 @@ static void stdiostream_vmessage(xentoollog_logger *logger_in,
                                  va_list al) {
     xentoollog_logger_stdiostream *lg = (void*)logger_in;
 
+    if (level < lg->min_level)
+        return;
+
     progress_erase(lg);
 
     if (lg->flags & XTL_STDIOSTREAM_SHOW_DATE) {
@@ -82,7 +85,7 @@ static void stdiostream_progress(struct xentoollog_logger *logger_in,
         this_level = XTL_PROGRESS;
     }
 
-    if (lg->min_level < this_level)
+    if (this_level < lg->min_level)
         return;
 
     if (lg->progress_erase_len)
index 8b106741de7f55a65f240ebc051258af21602d95..8ddba288d33bc5669245518c15c41404c252ba1b 100644 (file)
 #include "libxl_utils.h"
 #include "xl.h"
 
-xentoollog_logger *logger;
+xentoollog_logger_stdiostream *logger;
+
+static xentoollog_level minmsglevel = XTL_PROGRESS;
 
 int main(int argc, char **argv)
 {
-    int i;
+    int opt = 0, i;
+    char *cmd = 0;
+
+    while ((opt = getopt(argc, argv, "+v")) >= 0) {
+        switch (opt) {
+        case 'v':
+            if (minmsglevel > 0) minmsglevel--;
+            break;
+        default:
+            fprintf(stderr, "unknown global option\n");
+            exit(2);
+        }
+    }
+
+    cmd = argv[optind++];
 
-    if (argc < 2) {
+    if (!cmd) {
         help(NULL);
         exit(1);
     }
+    opterr = 0;
+
+    logger = xtl_createlogger_stdiostream(stderr, minmsglevel,  0);
+    if (!logger) exit(1);
 
-    logger = xtl_createlogger_stdiostream(stderr, XTL_PROGRESS,  0);
-    if (libxl_ctx_init(&ctx, LIBXL_VERSION, logger)) {
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION, (xentoollog_logger*)logger)) {
         fprintf(stderr, "cannot init xl context\n");
         exit(1);
     }
@@ -51,16 +70,13 @@ int main(int argc, char **argv)
     srand(time(0));
 
     for (i = 0; i < cmdtable_len; i++) {
-        if (!strcmp(argv[1], cmd_table[i].cmd_name))
-               cmd_table[i].cmd_impl(argc - 1, argv + 1);
+        if (!strcmp(cmd, cmd_table[i].cmd_name))
+               cmd_table[i].cmd_impl(argc, argv);
     }
 
     if (i >= cmdtable_len) {
-        if (!strcmp(argv[1], "help")) {
-            if (argc > 2)
-                help(argv[2]);
-            else
-                help(NULL);
+        if (!strcmp(cmd, "help")) {
+            help(argv[1]);
             exit(0);
         } else {
             fprintf(stderr, "command not implemented\n");
index 8b3644cb01cc07ac7ba28901e334d6a22b57d332..3144a64e0db2d6f32867e7936177415993e4d34f 100644 (file)
@@ -77,6 +77,6 @@ extern struct cmd_spec cmd_table[];
 extern int cmdtable_len;
 
 extern struct libxl_ctx ctx;
-extern xentoollog_logger *logger;
+extern xentoollog_logger_stdiostream *logger;
 
 #endif /* XL_H */