提交 034337fb 编写于 作者: E Erik Skultety

virlog: Introduce Type{To,From}String for virLogDestination

In order to refactor the ugly virLogParseOutputs method, this is a neat way of
finding out whether the destination type (in the form of a string) user
provided is a valid one. As a bonus, if it turns out it is valid, we get the
actual enum which will later be passed to any of virLogAddOutput methods right
away.
上级 6bd9758e
...@@ -73,6 +73,10 @@ static regex_t *virLogRegex; ...@@ -73,6 +73,10 @@ static regex_t *virLogRegex;
VIR_LOG_DATE_REGEX " " VIR_LOG_TIME_REGEX ": " \ VIR_LOG_DATE_REGEX " " VIR_LOG_TIME_REGEX ": " \
VIR_LOG_PID_REGEX ": " VIR_LOG_LEVEL_REGEX " : " VIR_LOG_PID_REGEX ": " VIR_LOG_LEVEL_REGEX " : "
VIR_ENUM_DECL(virLogDestination);
VIR_ENUM_IMPL(virLogDestination, VIR_LOG_TO_OUTPUT_LAST,
"stderr", "syslog", "file", "journald");
/* /*
* Filters are used to refine the rules on what to keep or drop * Filters are used to refine the rules on what to keep or drop
* based on a matching pattern (currently a substring) * based on a matching pattern (currently a substring)
...@@ -147,23 +151,6 @@ virLogUnlock(void) ...@@ -147,23 +151,6 @@ virLogUnlock(void)
} }
static const char *
virLogOutputString(virLogDestination ldest)
{
switch (ldest) {
case VIR_LOG_TO_STDERR:
return "stderr";
case VIR_LOG_TO_SYSLOG:
return "syslog";
case VIR_LOG_TO_FILE:
return "file";
case VIR_LOG_TO_JOURNALD:
return "journald";
}
return "unknown";
}
static const char * static const char *
virLogPriorityString(virLogPriority lvl) virLogPriorityString(virLogPriority lvl)
{ {
...@@ -1340,13 +1327,13 @@ virLogGetOutputs(void) ...@@ -1340,13 +1327,13 @@ virLogGetOutputs(void)
case VIR_LOG_TO_FILE: case VIR_LOG_TO_FILE:
virBufferAsprintf(&outputbuf, "%d:%s:%s", virBufferAsprintf(&outputbuf, "%d:%s:%s",
virLogOutputs[i].priority, virLogOutputs[i].priority,
virLogOutputString(dest), virLogDestinationTypeToString(dest),
virLogOutputs[i].name); virLogOutputs[i].name);
break; break;
default: default:
virBufferAsprintf(&outputbuf, "%d:%s", virBufferAsprintf(&outputbuf, "%d:%s",
virLogOutputs[i].priority, virLogOutputs[i].priority,
virLogOutputString(dest)); virLogDestinationTypeToString(dest));
} }
} }
virLogUnlock(); virLogUnlock();
......
...@@ -51,10 +51,11 @@ typedef enum { ...@@ -51,10 +51,11 @@ typedef enum {
# define VIR_LOG_DEFAULT VIR_LOG_WARN # define VIR_LOG_DEFAULT VIR_LOG_WARN
typedef enum { typedef enum {
VIR_LOG_TO_STDERR = 1, VIR_LOG_TO_STDERR = 0,
VIR_LOG_TO_SYSLOG, VIR_LOG_TO_SYSLOG,
VIR_LOG_TO_FILE, VIR_LOG_TO_FILE,
VIR_LOG_TO_JOURNALD, VIR_LOG_TO_JOURNALD,
VIR_LOG_TO_OUTPUT_LAST,
} virLogDestination; } virLogDestination;
typedef struct _virLogSource virLogSource; typedef struct _virLogSource virLogSource;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册