[libvirt] [PATCH 2/5] Several fixes to libvirtd's log setup
Daniel P. Berrange
berrange at redhat.com
Thu Aug 6 11:57:32 UTC 2009
On Fri, Jul 31, 2009 at 05:57:31PM -0400, Amy Griffis wrote:
> Similar as for general libvirt, don't convert high priority levels to debug
> level. Ignore LIBVIRT_LOG_FILTERS and LIBVIRT_LOG_OUTPUTS when they're set to
> the empty string, otherwise they can override a valid setting from the config
> file. Send all settings through the parser functions for validation, so that the
> existence of a bad setting doesn't nullify a good setting that should have
> applied -- particularly the default output. Keep the order of precedence
> consistent for all variables between the environment and the config file.
> Warn when an invalid log level, filter, or output is ignored.
> ---
>
> qemud/qemud.c | 82 +++++++++++++++++++++++++++-------------------
> src/libvirt_private.syms | 3 ++
> src/logging.c | 27 +++++++++++++++
> src/logging.h | 3 ++
> 4 files changed, 81 insertions(+), 34 deletions(-)
ACK
Daniel
>
> diff --git a/qemud/qemud.c b/qemud/qemud.c
> index 3e551ca..65c07d9 100644
> --- a/qemud/qemud.c
> +++ b/qemud/qemud.c
> @@ -132,11 +132,6 @@ static int timeout = -1; /* -t: Shutdown timeout */
> static int sigwrite = -1; /* Signal handler pipe */
> static int ipsock = 0; /* -l Listen for TCP/IP */
>
> -/* Defaults for logging */
> -static int log_level = VIR_LOG_DEFAULT;
> -static char *log_filters = NULL;
> -static char *log_outputs = NULL;
> -
> /* Defaults for configuration file elements */
> static int listen_tls = 1;
> static int listen_tcp = 0;
> @@ -2494,6 +2489,9 @@ remoteReadSaslAllowedUsernameList (virConfPtr conf ATTRIBUTE_UNUSED,
> static int
> qemudSetLogging(virConfPtr conf, const char *filename) {
> char *debugEnv;
> + int log_level;
> + char *log_filters = NULL;
> + char *log_outputs = NULL;
> int ret = -1;
>
> virLogReset();
> @@ -2503,54 +2501,70 @@ qemudSetLogging(virConfPtr conf, const char *filename) {
> * then from environment variable and finally from command
> * line options
> */
> + /*
> + * GET_CONF_INT returns 0 when there is no log_level setting in
> + * the config file. The conditional below eliminates a false
> + * warning in that case, but also has the side effect of missing
> + * a warning if the user actually does say log_level=0.
> + */
> GET_CONF_INT (conf, filename, log_level);
> + if (log_level != 0)
> + virLogSetDefaultPriority(log_level);
> +
> debugEnv = getenv("LIBVIRT_DEBUG");
> - if (debugEnv && *debugEnv && *debugEnv != '0') {
> - if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info"))
> - log_level = VIR_LOG_INFO;
> + if (debugEnv && *debugEnv) {
> + if (STREQ(debugEnv, "1") || STREQ(debugEnv, "debug"))
> + virLogSetDefaultPriority(VIR_LOG_DEBUG);
> + else if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info"))
> + virLogSetDefaultPriority(VIR_LOG_INFO);
> else if (STREQ(debugEnv, "3") || STREQ(debugEnv, "warning"))
> - log_level = VIR_LOG_WARN;
> + virLogSetDefaultPriority(VIR_LOG_WARN);
> else if (STREQ(debugEnv, "4") || STREQ(debugEnv, "error"))
> - log_level = VIR_LOG_ERROR;
> + virLogSetDefaultPriority(VIR_LOG_ERROR);
> else
> - log_level = VIR_LOG_DEBUG;
> + VIR_WARN0(_("Ignoring invalid log level setting."));
> + }
> +
> + if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO))
> + virLogSetDefaultPriority(VIR_LOG_INFO);
> +
> + debugEnv = getenv("LIBVIRT_LOG_FILTERS");
> + if (debugEnv && *debugEnv)
> + virLogParseFilters(strdup(debugEnv));
> +
> + if (virLogGetNbFilters() == 0) {
> + GET_CONF_STR (conf, filename, log_filters);
> + virLogParseFilters(log_filters);
> }
> - if ((verbose) && (log_level >= VIR_LOG_WARN))
> - log_level = VIR_LOG_INFO;
> - virLogSetDefaultPriority(log_level);
>
> /* there is no default filters */
> - GET_CONF_STR (conf, filename, log_filters);
> - if (!log_filters) {
> - debugEnv = getenv("LIBVIRT_LOG_FILTERS");
> - if (debugEnv)
> - log_filters = strdup(debugEnv);
> +
> + debugEnv = getenv("LIBVIRT_LOG_OUTPUTS");
> + if (debugEnv && *debugEnv)
> + virLogParseOutputs(strdup(debugEnv));
> +
> + if (virLogGetNbOutputs() == 0) {
> + GET_CONF_STR (conf, filename, log_outputs);
> + virLogParseOutputs(log_outputs);
> }
> - virLogParseFilters(log_filters);
>
> - /*
> - * by default save all warning and errors to syslog or
> - * all logs to stderr if not running as daemon
> + /*
> + * If no defined outputs, then direct to syslog when running
> + * as daemon. Otherwise the default output is stderr.
> */
> - GET_CONF_STR (conf, filename, log_outputs);
> - if (!log_outputs) {
> - debugEnv = getenv("LIBVIRT_LOG_OUTPUTS");
> - if (debugEnv)
> - log_outputs = strdup(debugEnv);
> - }
> - if (!log_outputs) {
> + if (virLogGetNbOutputs() == 0) {
> char *tmp = NULL;
> if (godaemon) {
> - if (virAsprintf (&tmp, "%d:syslog:libvirtd", log_level) < 0)
> + if (virAsprintf (&tmp, "%d:syslog:libvirtd",
> + virLogGetDefaultPriority()) < 0)
> goto free_and_fail;
> } else {
> - if (virAsprintf(&tmp, "%d:stderr", log_level) < 0)
> + if (virAsprintf (&tmp, "%d:stderr",
> + virLogGetDefaultPriority()) < 0)
> goto free_and_fail;
> }
> virLogParseOutputs(tmp);
> VIR_FREE(tmp);
> - } else {
> - virLogParseOutputs(log_outputs);
> }
> ret = 0;
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index bd63692..487585c 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -213,6 +213,9 @@ virRegisterDeviceMonitor;
>
> # logging.h
> virLogMessage;
> +virLogGetNbFilters;
> +virLogGetNbOutputs;
> +virLogGetDefaultPriority;
> virLogSetDefaultPriority;
> virLogDefineFilter;
> virLogDefineOutput;
> diff --git a/src/logging.c b/src/logging.c
> index 27d6e4b..aad4b50 100644
> --- a/src/logging.c
> +++ b/src/logging.c
> @@ -802,3 +802,30 @@ cleanup:
> VIR_WARN0(_("Ignoring invalid log filter setting."));
> return(ret);
> }
> +
> +/**
> + * virLogGetDefaultPriority:
> + *
> + * Returns the current logging priority level.
> + */
> +int virLogGetDefaultPriority(void) {
> + return (virLogDefaultPriority);
> +}
> +
> +/**
> + * virLogGetNbFilters:
> + *
> + * Returns the current number of defined log filters.
> + */
> +int virLogGetNbFilters(void) {
> + return (virLogNbFilters);
> +}
> +
> +/**
> + * virLogGetNbOutputs:
> + *
> + * Returns the current number of defined log outputs.
> + */
> +int virLogGetNbOutputs(void) {
> + return (virLogNbOutputs);
> +}
> diff --git a/src/logging.h b/src/logging.h
> index f1e2525..c8698e5 100644
> --- a/src/logging.h
> +++ b/src/logging.h
> @@ -105,6 +105,9 @@ typedef int (*virLogOutputFunc) (const char *category, int priority,
> */
> typedef void (*virLogCloseFunc) (void *data);
>
> +extern int virLogGetNbFilters(void);
> +extern int virLogGetNbOutputs(void);
> +extern int virLogGetDefaultPriority(void);
> extern int virLogSetDefaultPriority(int priority);
> extern int virLogDefineFilter(const char *match, int priority, int flags);
> extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c,
>
> --
> Libvir-list mailing list
> Libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
More information about the libvir-list
mailing list