This chapter covers the debugging and logging APIs in libvirt. This should supply you with enough information to solve runtime problems that sometimes occur with libvirt. Although the example programs in this book do not show how to incorporate debugging and logging in your program, there is enough information presented here to make that task easy enough.
Logging Facilities
libvirt includes logging facilities to facilitate the tracing of library execution. These logs will frequently be requested when trying to obtain support for libvirt, so familiarity with them is essential.
Log messages: Generated at runtime by the libvirt code, they include a timestamp, a priority level (DEBUG = 1, INFO = 2, WARNING = 3, ERROR = 4), a category, a function name, a line number indicating where the message originated, and a formatted message.
Log filters : These are patterns and priorities that control whether a particular message is displayed. The format for a filter is as follows:
x:namewhere x is the minimal priority level where the match should apply, and name is a string to match against. The priority levels are as follows:
1 (or DEBUG): Log all messages
2 (or INFO): Log all nondebugging information
3 (or WARNING): Log only warnings and errors; this is the default
4 (or ERROR): Log only errors
For instance, to log all debug messages to the qemu driver, the following filter can be used:1:qemuMultiple filters can be specified together with a space separating them; the following example logs all debug messages from qemu and logs all error messages from the remote driver:1:qemu 4:remoteLog outputs : The output specifies where to send the message once it has passed through filters. The format for the log output is one of the following:
x:stderr - log to stderrx:syslog:name - log to syslog with a prefix of "name"x:file:file_path - log to a file specified by "file_path"where x is the minimal priority level. For instance, to log all warnings and errors to syslog with a prefix of libvirtd, the following output can be used:3:syslog:libvirtdMultiple outputs can be specified with a space separating them; the following example logs all error and warning messages to syslog and logs all debug, information, warning, and error messages to /tmp/libvirt.log:3:syslog:libvirtd 1:file:/tmp/libvirt.log
Environment Variables
LIBVIRT_DEBUG specifies the minimum priority level of messages that will be logged. This can be thought of as a “global” priority level; if a particular log message does not match a specific filter in LIBVIRT_LOG_FILTERS, it will be compared to this global priority and logged as appropriate.
LIBVIRT_LOG_FILTERS specifies the filters to apply.
LIBVIRT_LOG_OUTPUTS specifies the outputs to send the message to.
Running virsh with Environment Variables
This example will only print error messages from virsh, except that the remote driver will print all debug, information, warning, and error messages.
Summary
This chapter covered the debugging and logging facilities in libvirt. The examples should give you enough information to be able to use them in your own programs.