译libvirt : debug and logging
You need to use some functions of libvirt to start the virtual machine, but qemu needs to print the log. libvirt gives the corresponding solution:
- LIBVIRT_DEBUG
- LIBVIRT_LOG_FILTERS
- LIBVIRT_LOG_OUTPUTS
Markdown and extensions
The logging facility in libvirt is based on 3 key concepts.
variable | value |
---|---|
Log messages | DEBUG = 1, INFO = 2, WARNING = 3, ERROR = 4 |
Log filters | x:name |
Log outputs | filename |
log messages represent the log level, and only output information whose log level is higher than the set level
1 (or debug) - log all messages
2 (or info) - log all non-debugging information
3 (or warn) - log only warnings and errors - this is the default
4 (or error) - log only errors
log filters indicate that the log output content is related
1:qemu //输出qemu相关的调试信息,日志等级为debug
log outputs represents the output path
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"
Example
LIBVIRT_DEBUG=error LIBVIRT_LOG_FILTERS=”1:qemu” LIBVIRT_LOG_OUTPUTS=”/var/log/libvirt/qemu/ubuntu12.log” virsh start ubuntu12
analysis:
start the Ubuntu2 virtual machine, enable log output: output information above the virsh error level, and Output the information above the qemu debug level to the /var/log/libvirt/qemu/ubuntu12.log file