]> git.proxmox.com Git - pve-cluster.git/commitdiff
use qblog instead of syslog
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 9 Feb 2012 08:47:40 +0000 (09:47 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 9 Feb 2012 08:47:40 +0000 (09:47 +0100)
data/src/cfs-utils.c
data/src/cfs-utils.h
data/src/check_memdb.c
data/src/create_pmxcfs_db.c
data/src/logtest.c
data/src/pmxcfs.c

index d3100216283ade50416b2026b11f099c117d9e30..721573db059ecc63d3301df65d775ae7cc9f1597 100644 (file)
@@ -31,7 +31,7 @@
 #include <utime.h>
 #include <sys/stat.h>
 #include <glib.h>
-#include <sys/syslog.h>
+#include <qb/qblog.h>
 
 #include "cfs-utils.h"
 
@@ -116,15 +116,6 @@ cfs_log(
        const gchar    *format,
        ...)
 {
-       va_list args;
-
-       va_start (args, format);
-       char *orgmsg = g_strdup_vprintf (format, args);
-       va_end (args);
-
-       char msg[8192];
-       utf8_to_ascii(msg, sizeof(msg), orgmsg, FALSE);
-
        gint level; 
        char *ltxt;
 
@@ -160,82 +151,22 @@ cfs_log(
                ltxt = "info";
        } 
 
-       if (!file || (log_level == G_LOG_LEVEL_MESSAGE ||
-                     log_level == G_LOG_LEVEL_INFO)) {
-
-               if (log_domain) {
-                       syslog(level, "[%s] %s", log_domain, msg); 
-
-                       if (cfs.debug || cfs.print_to_console)
-                               printf("%s: [%s] %s\n", ltxt, log_domain, msg);
-               } else {
-                       syslog(level, msg); 
-
-                       if (cfs.debug || cfs.print_to_console)
-                               printf("%s: %s\n", ltxt, msg);
-
-               }
+       va_list args;
 
-       } else {
+       va_start (args, format);
+       char *orgmsg = g_strdup_vprintf (format, args);
+       va_end (args);
 
-               if (log_domain) {
-                       syslog(level, "[%s] %s (%s:%d:%s)", log_domain, msg, file, line, func); 
+       char msg[8192];
+       utf8_to_ascii(msg, sizeof(msg), orgmsg, FALSE);
 
-                       if (cfs.debug || cfs.print_to_console)
-                               printf("%s: [%s] %s (%s:%d:%s)\n", ltxt, log_domain, msg, file, line, func);
+       uint32_t tag = g_quark_from_string(log_domain);
 
-               } else {
-                       syslog(level, "%s (%s:%d:%s)", msg, file, line, func); 
-
-                       if (cfs.debug || cfs.print_to_console)
-                               printf("%s: %s (%s:%d:%s)\n", ltxt, msg, file, line, func);
-               }
-       }
+       qb_log_from_external_source(func, file, "%s", level, line, tag, msg);
 
        g_free(orgmsg);
 }
 
-void ipc_log_fn(
-       const char *file,
-       int32_t line, 
-       int32_t severity, 
-       const char *msg)
-{
-
-       if (!cfs.debug && 
-           !(severity == LOG_ERR || severity == LOG_CRIT || severity == LOG_WARNING))
-               return;
-
-       GLogLevelFlags log_level;
-
-       switch (severity) { 
-       case LOG_ERR:
-               log_level = G_LOG_LEVEL_ERROR;
-               break; 
-       case LOG_CRIT:
-               log_level = G_LOG_LEVEL_CRITICAL; 
-               break; 
-       case LOG_WARNING:
-               log_level = G_LOG_LEVEL_WARNING;
-               break; 
-       case LOG_NOTICE:
-               log_level = G_LOG_LEVEL_MESSAGE;
-               break; 
-       case LOG_INFO:
-               log_level = G_LOG_LEVEL_INFO;
-               break; 
-       case LOG_DEBUG:
-               log_level = G_LOG_LEVEL_DEBUG;
-               if (!cfs.debug)
-                       return;
-               break; 
-       default:  
-               log_level = G_LOG_LEVEL_INFO;
-       }
-
-       cfs_log(G_LOG_DOMAIN, log_level, file, line, "", msg);
-}
-
 // xml parser for cluster.conf - just good enough to extract version
 
 typedef struct
index 324b499d26f37ea95af7318a7b322543f1c63d75..b088a9cfbc2b6fd87ecc6bf40f0a2c1cb66d7bc2 100644 (file)
@@ -41,7 +41,6 @@ typedef struct {
        char *ip;
        gid_t gid;
        int debug;
-       int print_to_console;
 } cfs_t;
 
 extern cfs_t cfs;
index 4a5ea344c61dd47f5f090900b20e0e49f0ab2392..261321a09a36fe5c2d0f256507102d8ceffb2e4f 100644 (file)
@@ -34,7 +34,6 @@
 cfs_t cfs = {
        .debug = 0,
        .nodename = "testnode",
-       .print_to_console = 1,
 };
 
 #define TESTDB "/tmp/test.db"
index dfc1fc8289abc7c88798df754cfd499d4eaab94b..fc4265423558a8d6c65c3e103f2b44a1fec73794 100644 (file)
@@ -38,7 +38,6 @@
 cfs_t cfs = {
        .debug = 0,
        .nodename = "dummy",
-       .print_to_console = 1,
 };
 
 static memdb_t *memdb;
index db707b2dce985a7c52050f8debd181293d62f451..2cac288249e8f5a7161e48fe9bdadaf330ffb18c 100644 (file)
@@ -39,7 +39,6 @@
 cfs_t cfs = {
         .debug = 0,
        .nodename = "testnode",
-        .print_to_console = 1,
 };
 
 
index 69b3fb2e18ba1b0edde9b2750266dce687c08074..546191c9453804676439d6807c931a90d14d21b3 100644 (file)
@@ -27,7 +27,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <glib.h>
-#include <syslog.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
@@ -45,6 +44,7 @@
  
 #include <qb/qbdefs.h>
 #include <qb/qbutil.h>
+#include <qb/qblog.h>
 
 #include "cfs-utils.h"
 #include "cfs-plug.h"
@@ -63,7 +63,6 @@
 
 cfs_t cfs = {
        .debug = 0,
-       .print_to_console = 1,
 };
 
 static struct fuse *fuse = NULL;
@@ -72,8 +71,7 @@ static cfs_plug_t *root_plug;
 
 static void glib_print_handler(const gchar *string)
 {
-       if (cfs.debug || cfs.print_to_console)
-               printf("%s", string);
+       printf("%s", string);
 }
 
 static void glib_log_handler(const gchar *log_domain,
@@ -562,6 +560,22 @@ read_debug_setting_cb(cfs_plug_t *plug)
        return g_strdup_printf("%d\n", !!cfs.debug); 
 }
 
+static void 
+update_qb_log_settings(void) 
+{
+       if (cfs.debug) {
+               qb_log_format_set(QB_LOG_SYSLOG, "[%g] %p: %b (%f:%l:%n)");
+               qb_log_format_set(QB_LOG_STDERR, "[%g] %p: %b (%f:%l:%n)");
+               qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP, LOG_INFO - LOG_DEBUG);
+               qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_PRIORITY_BUMP, LOG_INFO - LOG_DEBUG);
+       } else {
+               qb_log_format_set(QB_LOG_SYSLOG, "[%g] %p: %b");
+               qb_log_format_set(QB_LOG_STDERR, "[%g] %p: %b");
+               qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP, LOG_DEBUG - LOG_INFO);
+               qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_PRIORITY_BUMP, LOG_DEBUG - LOG_INFO);
+       }
+}
+
 static int write_debug_setting_cb(
        cfs_plug_t *plug, 
        const char *buf,
@@ -576,12 +590,14 @@ static int write_debug_setting_cb(
                if (cfs.debug) {
                        cfs_message("disable debug mode");
                        cfs.debug = 0;
+                       update_qb_log_settings();
                }
                return 2;
        } else if (strncmp(buf, "1\n", 2) == 0) {
                if (!cfs.debug) {
-                       cfs_message("enable debug mode");
                        cfs.debug = 1;
+                       update_qb_log_settings();
+                       cfs_message("enable debug mode");
                }
                return 2;
        }
@@ -655,6 +671,22 @@ lookup_node_ip(const char *nodename)
 
        return NULL;
 }
+
+static const char* 
+log_tags_stringify(uint32_t tags) {
+       if (qb_bit_is_set(tags, QB_LOG_TAG_LIBQB_MSG_BIT)) {
+               return "libqb";
+       } else {
+               GQuark quark = tags;
+               const char *domain = g_quark_to_string(quark);
+               if (domain != NULL) {
+                       return domain;
+               } else {
+                       return "main";
+               }
+       }
+}
+
 int main(int argc, char *argv[])
 {
        int ret = -1;
@@ -667,7 +699,14 @@ int main(int argc, char *argv[])
        dfsm_t *dcdb = NULL;
        dfsm_t *status_fsm = NULL;
 
-       openlog("pmxcfs", LOG_PID, LOG_DAEMON);
+       qb_log_init("pmxcfs", LOG_DAEMON, LOG_DEBUG);
+       qb_log_tags_stringify_fn_set(log_tags_stringify);
+
+       qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
+       qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
+                         QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
+
+       update_qb_log_settings();
 
        g_set_print_handler(glib_print_handler);
        g_set_printerr_handler(glib_print_handler);
@@ -691,18 +730,25 @@ int main(int argc, char *argv[])
        {
                cfs_critical("option parsing failed: %s", err->message);
                g_error_free (err);
+               qb_log_fini();
                exit (1);
        }
        g_option_context_free(context);
 
        if (optind < argc) {
                cfs_critical("too many arguments");
+               qb_log_fini();
                exit(-1);
        }
-               
+
+       if (cfs.debug) {
+               update_qb_log_settings();
+       }
+
        struct utsname utsname;
        if (uname(&utsname) != 0) {
                cfs_critical("Unable to read local node name");
+               qb_log_fini();
                exit (-1);
        }
        
@@ -714,20 +760,20 @@ int main(int argc, char *argv[])
 
        if (!(cfs.ip = lookup_node_ip(cfs.nodename))) { 
                cfs_critical("Unable to get local IP address");
+               qb_log_fini();
                exit(-1);
        }
 
        struct group *www_data = getgrnam("www-data");
        if (!www_data) {
                cfs_critical("Unable to get www-data group ID");
+               qb_log_fini();
                exit (-1);
        }
        cfs.gid = www_data->gr_gid;
 
        g_thread_init(NULL);
 
-       qb_util_set_log_function(ipc_log_fn);
-
        umask(027);
 
        mkdir(VARLIBDIR, 0755);
@@ -828,6 +874,7 @@ int main(int argc, char *argv[])
                        goto err;
                } else if (cpid) {
                        write_pidfile(cpid);
+                       qb_log_fini();
                        _exit (0);
                } else {
                        int nullfd;
@@ -843,7 +890,8 @@ int main(int argc, char *argv[])
                        }
 
                        // do not print to the console after this point
-                       cfs.print_to_console = 0;
+                       qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_FALSE);
+
                        setsid();
                }
        } else {
@@ -934,6 +982,8 @@ int main(int argc, char *argv[])
 
        cfs_status_cleanup();
 
+       qb_log_fini();
+
        exit(ret);
 
  err: