Several fixes to libvirtd's log setup

* qemud/qemud.c src/logging.[ch]: 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.
* src/libvirt_private.syms: export internally a few convenience functions
This commit is contained in:
Amy Griffis 2009-08-06 15:45:50 +02:00 committed by Daniel Veillard
parent 22a1ec68d5
commit 9147bf2a73
4 changed files with 80 additions and 33 deletions

View File

@ -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;

View File

@ -213,6 +213,9 @@ virRegisterDeviceMonitor;
# logging.h
virLogMessage;
virLogGetNbFilters;
virLogGetNbOutputs;
virLogGetDefaultPriority;
virLogSetDefaultPriority;
virLogDefineFilter;
virLogDefineOutput;

View File

@ -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);
}

View File

@ -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,