© W. David Ashley 2019
W. David AshleyFoundations of Libvirt Development https://doi.org/10.1007/978-1-4842-4862-1_11

11. Debugging/Logging

W. David Ashley1 
(1)
Austin, TX, USA
 

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.

The logging facilities in libvirt are based on three key concepts.
  • 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:name

    where 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:qemu
    Multiple 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:remote
  • Log 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 stderr
    x: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:libvirtd
    Multiple 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

The desired log priority level, filters, and outputs are specified to the libvirt library through the use of 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.

To see more detailed information about virsh errors, you can run virsh after setting the following environment variables:
LIBVIRT_DEBUG=error
LIBVIRT_LOG_FILTERS="1:remote"
virsh list
Listing 11-1

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.216.18