mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
virlog: Split parsing and setting priority
Handling of outputs and filters has been changed in a way that splits parsing and defining. Do the same thing for logging priority as well, this however, doesn't need much of a preparation. Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
adda3e4f9b
commit
6fe47467cb
@ -220,7 +220,9 @@ int
|
|||||||
virLogSetDefaultPriority(virLogPriority priority)
|
virLogSetDefaultPriority(virLogPriority priority)
|
||||||
{
|
{
|
||||||
if ((priority < VIR_LOG_DEBUG) || (priority > VIR_LOG_ERROR)) {
|
if ((priority < VIR_LOG_DEBUG) || (priority > VIR_LOG_ERROR)) {
|
||||||
VIR_WARN("Ignoring invalid log level setting.");
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("Failed to set logging priority, argument '%u' is "
|
||||||
|
"invalid"), priority);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (virLogInitialize() < 0)
|
if (virLogInitialize() < 0)
|
||||||
@ -1141,34 +1143,33 @@ virLogGetNbOutputs(void)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* virLogParseDefaultPriority:
|
* virLogParseDefaultPriority:
|
||||||
* @priority: string defining the desired logging level
|
* @priority: string defining the desired logging level (either a numeric or a
|
||||||
|
* word form, see below)
|
||||||
*
|
*
|
||||||
* Parses and sets the default log priority level. It can take a string or
|
* Parses the desired log priority level. The input @priority shall conform to
|
||||||
* number corresponding to the following levels:
|
* one of the following levels:
|
||||||
* 1: DEBUG
|
* 1 = DEBUG
|
||||||
* 2: INFO
|
* 2 = INFO
|
||||||
* 3: WARNING
|
* 3 = WARNING
|
||||||
* 4: ERROR
|
* 4 = ERROR
|
||||||
*
|
*
|
||||||
* Returns 0 if successful, -1 in case of error.
|
*
|
||||||
|
* Returns the corresponding priority enum on success, -1 in case of error. A
|
||||||
|
* call to virLogSetDefaultPriority should be issued upon returning from this
|
||||||
|
* function.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virLogParseDefaultPriority(const char *priority)
|
virLogParseDefaultPriority(const char *priority)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (STREQ(priority, "1") || STREQ(priority, "debug"))
|
if (STREQ(priority, "1") || STREQ(priority, "debug"))
|
||||||
ret = virLogSetDefaultPriority(VIR_LOG_DEBUG);
|
return VIR_LOG_DEBUG;
|
||||||
else if (STREQ(priority, "2") || STREQ(priority, "info"))
|
else if (STREQ(priority, "2") || STREQ(priority, "info"))
|
||||||
ret = virLogSetDefaultPriority(VIR_LOG_INFO);
|
return VIR_LOG_INFO;
|
||||||
else if (STREQ(priority, "3") || STREQ(priority, "warning"))
|
else if (STREQ(priority, "3") || STREQ(priority, "warning"))
|
||||||
ret = virLogSetDefaultPriority(VIR_LOG_WARN);
|
return VIR_LOG_WARN;
|
||||||
else if (STREQ(priority, "4") || STREQ(priority, "error"))
|
else if (STREQ(priority, "4") || STREQ(priority, "error"))
|
||||||
ret = virLogSetDefaultPriority(VIR_LOG_ERROR);
|
return VIR_LOG_ERROR;
|
||||||
else
|
return -1;
|
||||||
VIR_WARN("Ignoring invalid log level setting");
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1188,7 +1189,7 @@ virLogSetFromEnv(void)
|
|||||||
|
|
||||||
debugEnv = virGetEnvAllowSUID("LIBVIRT_DEBUG");
|
debugEnv = virGetEnvAllowSUID("LIBVIRT_DEBUG");
|
||||||
if (debugEnv && *debugEnv)
|
if (debugEnv && *debugEnv)
|
||||||
virLogParseDefaultPriority(debugEnv);
|
virLogSetDefaultPriority(virLogParseDefaultPriority(debugEnv));
|
||||||
debugEnv = virGetEnvAllowSUID("LIBVIRT_LOG_FILTERS");
|
debugEnv = virGetEnvAllowSUID("LIBVIRT_LOG_FILTERS");
|
||||||
if (debugEnv && *debugEnv)
|
if (debugEnv && *debugEnv)
|
||||||
virLogSetFilters(debugEnv);
|
virLogSetFilters(debugEnv);
|
||||||
|
@ -311,7 +311,8 @@ mymain(void)
|
|||||||
if (virThreadInitialize() < 0)
|
if (virThreadInitialize() < 0)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
char *debugEnv = getenv("LIBVIRT_DEBUG");
|
char *debugEnv = getenv("LIBVIRT_DEBUG");
|
||||||
if (debugEnv && *debugEnv && (virLogParseDefaultPriority(debugEnv) == -1)) {
|
if (debugEnv && *debugEnv &&
|
||||||
|
(virLogSetDefaultPriority(virLogParseDefaultPriority(debugEnv)) < 0)) {
|
||||||
fprintf(stderr, "Invalid log level setting.\n");
|
fprintf(stderr, "Invalid log level setting.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user