specify a "script log level" on the commandline to set under which log
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 16 Oct 2008 20:56:12 +0000 (07:56 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 16 Oct 2008 20:56:12 +0000 (07:56 +1100)
level any/all output from eventscripts will be logged as

include/ctdb_private.h
server/ctdb_logging.c
server/ctdbd.c

index 7bcd4a97003012beba6cf8676c162009a2b0c739..756c62ab7d9b193cc09599c5adf34361f98423ab 100644 (file)
@@ -1423,4 +1423,6 @@ void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
 
 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
 
+extern int script_log_level;
+
 #endif
index f551088b00ddeef63cb1b27380aa4c3f16a12ff2..06c7eb8b694f7b6cac128b9912480f6cd0f0df93 100644 (file)
@@ -151,6 +151,8 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
                ctdb->log->buf_used += n;
        }
 
+       this_log_level = script_log_level;
+
        while (ctdb->log->buf_used > 0 &&
               (p = memchr(ctdb->log->buf, '\n', ctdb->log->buf_used)) != NULL) {
                int n1 = (p - ctdb->log->buf)+1;
@@ -159,7 +161,9 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
                if (n2 > 0 && ctdb->log->buf[n2-1] == '\r') {
                        n2--;
                }
-               do_debug("%*.*s\n", n2, n2, ctdb->log->buf);
+               if (script_log_level <= LogLevel) {
+                       do_debug("%*.*s\n", n2, n2, ctdb->log->buf);
+               }
                memmove(ctdb->log->buf, p+1, sizeof(ctdb->log->buf) - n1);
                ctdb->log->buf_used -= n1;
        }
@@ -167,8 +171,10 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
        /* the buffer could have completely filled - unfortunately we have
           no choice but to dump it out straight away */
        if (ctdb->log->buf_used == sizeof(ctdb->log->buf)) {
-               do_debug("%*.*s\n", 
-                        (int)ctdb->log->buf_used, (int)ctdb->log->buf_used, ctdb->log->buf);
+               if (script_log_level <= LogLevel) {
+                       do_debug("%*.*s\n", 
+                               (int)ctdb->log->buf_used, (int)ctdb->log->buf_used, ctdb->log->buf);
+               }
                ctdb->log->buf_used = 0;
        }
 }
index 4dc0f74b2094384bea0d7154879f145d0fea9bcf..8e15df00fb056068dd820e2f926ed5df486129f2 100644 (file)
@@ -46,6 +46,7 @@ static struct {
        int         no_lmaster;
        int         no_recmaster;
        int         lvs;
+       int         script_log_level;
 } options = {
        .nlist = ETCDIR "/ctdb/nodes",
        .transport = "tcp",
@@ -53,8 +54,10 @@ static struct {
        .logfile = VARDIR "/log/log.ctdb",
        .db_dir = VARDIR "/ctdb",
        .db_dir_persistent = VARDIR "/ctdb/persistent",
+       .script_log_level = DEBUG_ERR,
 };
 
+int script_log_level;
 
 /*
   called by the transport layer when a packet comes in
@@ -126,6 +129,7 @@ int main(int argc, const char *argv[])
                { "no-lmaster", 0, POPT_ARG_NONE, &options.no_lmaster, 0, "disable lmaster role on this node", NULL },
                { "no-recmaster", 0, POPT_ARG_NONE, &options.no_recmaster, 0, "disable recmaster role on this node", NULL },
                { "lvs", 0, POPT_ARG_NONE, &options.lvs, 0, "lvs is enabled on this node", NULL },
+               { "script-log-level", 0, POPT_ARG_INT, &options.script_log_level, DEBUG_ERR, "log level of event script output", NULL },
                POPT_TABLEEND
        };
        int opt, ret;
@@ -167,6 +171,8 @@ int main(int argc, const char *argv[])
 
        ctdb->start_as_disabled = options.start_as_disabled;
 
+       script_log_level = options.script_log_level;
+
        ret = ctdb_set_logfile(ctdb, options.logfile, options.use_syslog);
        if (ret == -1) {
                printf("ctdb_set_logfile to %s failed - %s\n",