The lxc controller can't see libvirtd's log level setting so it needs to re-query it from the environment. The parsing code has a few users now, so I added a new function to the internal API, virLogParseDefaultPriority() along the lines of the other parse functions. Signed-off-by: Amy Griffis <amy.griffis@xxxxxx> diff --git a/qemud/qemud.c b/qemud/qemud.c index a58a767..bd17ccb 100644 --- a/qemud/qemud.c +++ b/qemud/qemud.c @@ -2465,16 +2465,8 @@ qemudSetLogging(virConfPtr conf, const char *filename) { */ GET_CONF_INT (conf, filename, log_level); debugEnv = getenv("LIBVIRT_DEBUG"); - if (debugEnv && *debugEnv && *debugEnv != '0') { - if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info")) - log_level = VIR_LOG_INFO; - else if (STREQ(debugEnv, "3") || STREQ(debugEnv, "warning")) - log_level = VIR_LOG_WARN; - else if (STREQ(debugEnv, "4") || STREQ(debugEnv, "error")) - log_level = VIR_LOG_ERROR; - else - log_level = VIR_LOG_DEBUG; - } + if (debugEnv && *debugEnv && *debugEnv != '0') + log_level = virLogParseDefaultPriority(debugEnv); if ((verbose) && (log_level >= VIR_LOG_WARN)) log_level = VIR_LOG_INFO; virLogSetDefaultPriority(log_level); diff --git a/src/libvirt.c b/src/libvirt.c index bf49018..a3f36da 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -258,6 +258,7 @@ virInitialize(void) { #ifdef ENABLE_DEBUG char *debugEnv; + int logPrio; #endif if (initialized) return(0); @@ -272,14 +273,8 @@ virInitialize(void) #ifdef ENABLE_DEBUG debugEnv = getenv("LIBVIRT_DEBUG"); if (debugEnv && *debugEnv && *debugEnv != '0') { - if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info")) - virLogSetDefaultPriority(VIR_LOG_INFO); - else if (STREQ(debugEnv, "3") || STREQ(debugEnv, "warning")) - virLogSetDefaultPriority(VIR_LOG_WARN); - else if (STREQ(debugEnv, "4") || STREQ(debugEnv, "error")) - virLogSetDefaultPriority(VIR_LOG_ERROR); - else - virLogSetDefaultPriority(VIR_LOG_DEBUG); + logPrio = virLogParseDefaultPriority(debugEnv); + virLogSetDefaultPriority(logPrio); } debugEnv = getenv("LIBVIRT_LOG_FILTERS"); if (debugEnv) diff --git a/src/libvirt_debug.syms b/src/libvirt_debug.syms index 1742a0b..539d879 100644 --- a/src/libvirt_debug.syms +++ b/src/libvirt_debug.syms @@ -12,6 +12,7 @@ virLogMessage; virLogSetDefaultPriority; virLogDefineFilter; virLogDefineOutput; +virLogParseDefaultPriority; virLogParseFilters; virLogParseOutputs; virLogStartup; diff --git a/src/logging.c b/src/logging.c index 83e07cc..c72d52e 100644 --- a/src/logging.c +++ b/src/logging.c @@ -793,5 +793,30 @@ int virLogParseFilters(const char *filters) { } return(ret); } + +/** + * virLogParseDefaultPriority: + * @priority: string defining the desired logging behavior + * + * It can take a string or number corresponding to the following log + * levels: + * 1: DEBUG + * 2: INFO + * 3: WARNING + * 4: ERROR + * + * DEBUG is returned if @priority doesn't match any of the other values. + */ +int virLogParseDefaultPriority(const char *priority) { + + if (STREQ(priority, "2") || STREQ(priority, "info")) + return VIR_LOG_INFO; + else if (STREQ(priority, "3") || STREQ(priority, "warning")) + return VIR_LOG_WARN; + else if (STREQ(priority, "4") || STREQ(priority, "error")) + return VIR_LOG_ERROR; + else + return VIR_LOG_DEBUG; +} #endif /* ENABLE_DEBUG */ diff --git a/src/logging.h b/src/logging.h index 7ea8935..72b3119 100644 --- a/src/logging.h +++ b/src/logging.h @@ -110,6 +110,7 @@ typedef void (*virLogCloseFunc) (void *data); #ifdef ENABLE_DEBUG +extern int virLogParseDefaultPriority(const char *priority); extern int virLogSetDefaultPriority(int priority); extern int virLogDefineFilter(const char *match, int priority, int flags); extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, @@ -130,6 +131,7 @@ extern void virLogMessage(const char *category, int priority, #else /* ENABLE_DEBUG */ +#define virLogParseDefaultPriority(p) #define virLogSetDefaultPriority(p) #define virLogDefineFilter(m, p, f) #define virLogDefineOutput(func, c, d, p, f) diff --git a/src/lxc_controller.c b/src/lxc_controller.c index 356ecb8..9355d39 100644 --- a/src/lxc_controller.c +++ b/src/lxc_controller.c @@ -594,6 +594,8 @@ int main(int argc, char *argv[]) int monitor = -1; int appPty = -1; int bg = 0; + char *debugEnv; + int logPrio; virCapsPtr caps = NULL; virDomainDefPtr def = NULL; char *configFile = NULL; @@ -735,6 +737,13 @@ int main(int argc, char *argv[]) } } + /* New programs need to re-query and set the libvirt log level. */ + debugEnv = getenv("LIBVIRT_DEBUG"); + if (debugEnv && *debugEnv && *debugEnv != '0') { + logPrio = virLogParseDefaultPriority(debugEnv); + virLogSetDefaultPriority(logPrio); + } + /* Accept initial client which is the libvirtd daemon */ if ((client = accept(monitor, NULL, 0)) < 0) { virReportSystemError(NULL, errno, "%s", -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list