On Mon, Apr 06, 2026 at 23:29:18 -0400, Laine Stump via Devel wrote:
> From: Laine Stump <[email protected]>
> 
> The same thing happens for each line of the log banner:
> 
> 1) A helper function is called that a) creates a "raw" string (just
>    the desired info, e.g. version string) and b) calls
>    virLogFormatString() for create a "cooked" version of the string
>    (containing thread-id and log priority)
> 2) the outputFunc for the target is called with strings (a) and (b)
> 
> By making a helper that does (1b) & (2), we can further reduce the
> amount of redundant code that needs to be written to add another line
> to the banner - now all we need to do is:
> 
> 1) create the raw string
> 2) call the helper, sending it the raw string
> 
> Signed-off-by: Laine Stump <[email protected]>
> ---
>  src/util/virlog.c | 81 +++++++++++++++++++++++------------------------
>  1 file changed, 39 insertions(+), 42 deletions(-)

Ah, this addresses comment from 3/6.


> 
> diff --git a/src/util/virlog.c b/src/util/virlog.c
> index 7a9b1e75d5..4e95af047b 100644
> --- a/src/util/virlog.c
> +++ b/src/util/virlog.c
> @@ -433,30 +433,6 @@ virLogFormatString(char **msg,
>  }
>  
>  
> -static void
> -virLogVersionString(const char **rawmsg,
> -                    char **msg)
> -{
> -    *rawmsg = VIR_LOG_VERSION_STRING;
> -    virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING);
> -}
> -
> -/* Similar to virGetHostname() but avoids use of error
> - * reporting APIs or logging APIs, to prevent recursion
> - */
> -static void
> -virLogHostnameString(char **rawmsg,
> -                     char **msg)
> -{
> -    char *hoststr;
> -
> -    hoststr = g_strdup_printf("hostname: %s", g_get_host_name());
> -
> -    virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, hoststr);
> -    *rawmsg = hoststr;
> -}
> -
> -
>  static void
>  virLogSourceUpdate(virLogSource *source)
>  {
> @@ -479,6 +455,33 @@ virLogSourceUpdate(virLogSource *source)
>  }
>  
>  
> +/**
> + * virLogOneInitMsg:
> + *
> + *  @str:    the "raw" form of the string that's going to be logged
> + *
> + * (the args are all described in the caller - virLogToOneTarget()
> + * @timestamp,@outputFunc, @data
> + *
> + * send one "init message" (the lines that are at the beginning of the
> + * log when a new daemon starts) to one target. This just creates the
> + * "fancy" version of the string with thread-id and priority, and
> + * sends that, along with the "raw" version of the string, to the log
> + * target at INFO level.
> + */
> +static void virLogOneInitMsg(const char *timestamp,
> +                             const char *str,
> +                             virLogOutputFunc outputFunc,
> +                             void *data)

Please use the contemporary formatting. 'static void' on separate line,
fuction name starting at col 1.

> +{
> +    g_autofree char *msg = NULL;
> +
> +    virLogFormatString(&msg, 0, NULL, VIR_LOG_INFO, str);
> +    outputFunc(&virLogSelf, VIR_LOG_INFO, __FILE__, __LINE__, __func__,
> +               timestamp, NULL, str, msg, data);
> +}
> +
> +
>  /**
>   * virLogToOneTarget:
>   *

Reviewed-by: Peter Krempa <[email protected]>

Reply via email to