[libvirt] [PATCH v2 13/20] virlog: Introduce virLogSetOutputs
John Ferlan
jferlan at redhat.com
Wed Sep 21 18:41:32 UTC 2016
On 08/18/2016 07:47 AM, Erik Skultety wrote:
> This API is the entry point to output modification of the logger. Currently,
> everything is done by virLogParseAndDefineOutputs. Parsing and defining will be
> split into two operations both handled by this method transparently.
>
> Signed-off-by: Erik Skultety <eskultet at redhat.com>
> ---
> src/libvirt_private.syms | 1 +
> src/util/virlog.c | 31 +++++++++++++++++++++++++++++++
> src/util/virlog.h | 1 +
> 3 files changed, 33 insertions(+)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 063fe5f..5fb30e6 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1876,6 +1876,7 @@ virLogProbablyLogMessage;
> virLogReset;
> virLogSetDefaultPriority;
> virLogSetFromEnv;
> +virLogSetOutputs;
> virLogUnlock;
> virLogVMessage;
>
> diff --git a/src/util/virlog.c b/src/util/virlog.c
> index 4b2aa4d..a60c027 100644
> --- a/src/util/virlog.c
> +++ b/src/util/virlog.c
> @@ -2110,3 +2110,34 @@ virLogParseFilters(const char *src, virLogFilterPtr **filters)
> virStringFreeList(strings);
> return ret;
> }
> +
> +/**
> + * virLogSetOutputs:
> + * @outputs: string defining a (set of) output(s)
> + *
> + * Replaces the current set of defined outputs with a new set of outputs.
> + *
> + * Returns the number of outputs successfully defined or -1 in case of an
> + * error.
> + */
> +int
> +virLogSetOutputs(const char *src)
> +{
> + int ret = -1;
> + int noutputs = 0;
> + virLogOutputPtr *outputs = NULL;
> +
> + if (virLogInitialize() < 0)
> + return -1;
> +
> + if ((noutputs = virLogParseOutputs(src, &outputs)) < 0)
> + goto cleanup;
> +
> + if ((ret = virLogDefineOutputs(outputs, noutputs)) < 0)
> + goto cleanup;
> +
If you set outputs = NULL here, then the following "if (ret < 0)" isn't
necessary
> + cleanup:
> + if (ret < 0)
> + virLogOutputListFree(outputs, noutputs);
> + return ret;
> +}
> diff --git a/src/util/virlog.h b/src/util/virlog.h
> index 9ccc650..88e6ac8 100644
> --- a/src/util/virlog.h
> +++ b/src/util/virlog.h
> @@ -197,6 +197,7 @@ void virLogOutputFree(virLogOutputPtr output);
> void virLogOutputListFree(virLogOutputPtr *list, int count);
> void virLogFilterFree(virLogFilterPtr filter);
> void virLogFilterListFree(virLogFilterPtr *list, int count);
> +int virLogSetOutputs(const char *outputs);
s/;/ ATTRIBUTE_NONNULL(1);
ACK w/ adjustments
John
>
> /*
> * Internal logging API
>
More information about the libvir-list
mailing list