[PATCH 03/18] virRaiseErrorLog: Don't skip error printing when enabling debug logging env variable

Peter Krempa posted 18 patches 1 year, 7 months ago
[PATCH 03/18] virRaiseErrorLog: Don't skip error printing when enabling debug logging env variable
Posted by Peter Krempa 1 year, 7 months ago
When a user requests debug logging by setting the environment variable:

LIBVIRT_DEBUG=1

we should log any errors regardless of the setting of e.g.
'LIBVIRT_LOG_OUTPUTS' as the code will log every 'debug' and 'info'
level message to stderr but will skip 'error' level messages.

This obviously makes debugging things very complicated as you can get to
a situation when the error itself is missing.

This can happen e.g. in tests.

Fix the issue by probing the default log level and calling the logger if
it's set for VIR_LOG_DEBUG.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/util/virerror.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virerror.c b/src/util/virerror.c
index 0bfa803b1f..453f19514e 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -775,9 +775,11 @@ void virRaiseErrorLog(const char *filename,
      * hate & thus disable that too. If the daemon has set
      * a priority filter though, we should always forward
      * all errors to the logging code.
+     * Similarly when debug priority is the default we want to log the error.
      */
     if (virLogGetNbOutputs() > 0 ||
-        virErrorLogPriorityFilter)
+        virErrorLogPriorityFilter ||
+        virLogGetDefaultPriority() == VIR_LOG_DEBUG)
         virLogMessage(&virLogSelf,
                       priority,
                       filename, linenr, funcname,
-- 
2.40.1
Re: [PATCH 03/18] virRaiseErrorLog: Don't skip error printing when enabling debug logging env variable
Posted by Jonathon Jongsma 1 year, 7 months ago
On 5/25/23 10:13 AM, Peter Krempa wrote:
> When a user requests debug logging by setting the environment variable:
> 
> LIBVIRT_DEBUG=1
> 
> we should log any errors regardless of the setting of e.g.
> 'LIBVIRT_LOG_OUTPUTS' as the code will log every 'debug' and 'info'
> level message to stderr but will skip 'error' level messages.
> 
> This obviously makes debugging things very complicated as you can get to
> a situation when the error itself is missing.
> 
> This can happen e.g. in tests.
> 
> Fix the issue by probing the default log level and calling the logger if
> it's set for VIR_LOG_DEBUG.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>   src/util/virerror.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/util/virerror.c b/src/util/virerror.c
> index 0bfa803b1f..453f19514e 100644
> --- a/src/util/virerror.c
> +++ b/src/util/virerror.c
> @@ -775,9 +775,11 @@ void virRaiseErrorLog(const char *filename,
>        * hate & thus disable that too. If the daemon has set
>        * a priority filter though, we should always forward
>        * all errors to the logging code.
> +     * Similarly when debug priority is the default we want to log the error.
>        */
>       if (virLogGetNbOutputs() > 0 ||
> -        virErrorLogPriorityFilter)
> +        virErrorLogPriorityFilter ||
> +        virLogGetDefaultPriority() == VIR_LOG_DEBUG)
>           virLogMessage(&virLogSelf,
>                         priority,
>                         filename, linenr, funcname,


LIBVIRT_DEBUG accepts the following values: (1 or "debug"), (2 or 
"info"), (3 or "warning"), and (4 or "error"). In addition, the 
--verbose option sets the default log priority to VIR_LOG_INFO. It seems 
a little bit odd to add a workaround only for the "debug" case.

Jonathon