WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 11/14] xl: Allow control of logging level.

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 11/14] xl: Allow control of logging level.
From: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Date: Thu, 27 May 2010 17:01:11 +0100
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Delivery-date: Thu, 27 May 2010 09:32:14 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1274976074-3965-11-git-send-email-ian.jackson@xxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1274976074-3965-1-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-2-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-3-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-4-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-5-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-6-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-7-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-8-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-9-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-10-git-send-email-ian.jackson@xxxxxxxxxxxxx> <1274976074-3965-11-git-send-email-ian.jackson@xxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxx>
---
 tools/libxc/xtl_logger_stdio.c |    5 ++++-
 tools/libxl/xl.c               |   40 ++++++++++++++++++++++++++++------------
 tools/libxl/xl.h               |    2 +-
 3 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/tools/libxc/xtl_logger_stdio.c b/tools/libxc/xtl_logger_stdio.c
index 587c67d..abe274a 100644
--- a/tools/libxc/xtl_logger_stdio.c
+++ b/tools/libxc/xtl_logger_stdio.c
@@ -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)
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index 8b10674..8ddba28 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -31,19 +31,38 @@
 #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");
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 8b3644c..3144a64 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -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 */
-- 
1.5.6.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>