Logging in the library and the daemon

Libvirt includes logging facilities starting from version 0.6.0, this complements the error handling mechanism and APIs to allow tracing though the execution of the library as well as in the libvirtd daemon.

The logging functionalities in libvirt are based on 3 key concepts, similar to the one present in other generic logging facilities like log4j:

The library configuration of logging is though 3 environment variables allowing to control the logging behaviour:

Similary the daemon logging behaviour can be tuned using 3 config variables, stored in the configuration file:

In both case the syntax for filters and outputs is similar.

The format for a filter is:

x:name

where name is a match string e.g. remote or qemu and the x is the minimal level where matching messages should be logged:

Multiple filter can be defined in a single string, they just need to be separated by spaces, e.g: "3:remote 4:event" to only get warning or errors from the remote layer and only errors from the event layer.

The format for an output can be one of those 3 forms:

In all cases the x prefix is the minimal level, acting as a filter:

Multiple output can be defined , they just need to be separated by spaces, e.g.: "3:syslog:libvirtd 0:file:/tmp/libvirt.log" will log all warnings and errors to syslog under the libvirtd ident but also log everything debugging and informations included in the file /tmp/libvirt.log

For example setting up the following:

export LIBVIRT_DEBUG=1
export LIBVIRT_LOG_OUTPUTS="0:file:virsh.log"

and then running virsh will accumulate the logs in the virsh.log file in a way similar to:

14:29:04.771: debug : virInitialize:278 : register drivers
14:29:04.771: debug : virRegisterDriver:618 : registering Test as driver 0

the messages are timestamped, there is also the level recorded, if debug the name of the function is also printed and then the formatted message. This should be sufficient to at least get a precise idea of what is happening and where things are going wrong, allowing to then put the correct breakpoints when running under a debugger.