During the operation of UHD, logging messages are created which UHD handles in a logging subsystem. Everything logging-related is defined in include/uhd/utils/log.hpp. See also The UHD logging facility
UHD itself never prints anything to stdout, which means that stdout can be used for applications using UHD. Actual logging messages are handled by separate logging backends. By default, UHD has two backends: A console backend, which prints logging messages to stderr (more accurately, to std::clog
), and a file backend, which writes all logging messages into a log file.
UHD defines the following log levels (see also Log levels):
Whenever a log level is set, it means all log levels with higher severity are also printed. Example: If the log level is set to 'debug', it won't print messages that are at 'trace' severity, but it will print 'info' and all the other levels.
There are multiple ways to set the log level:
Log levels are evaluated in this order. If the minimum level is 'debug', no 'trace' message will ever be printed. If the global level is 'info', no 'debug' message will ever be printed – but this can be changed at runtime. Finally, if a message has passed both the minimum and global levels, it is handled by the individual backends if their log levels are appropriately set.
For more info on how to set the individual log levels, see include/uhd/utils/log.hpp.
When log messages are generated, the appropriate logging macros should always be used. There are two types of macros:
The difference between those is, the former style is completely compiled out when the minimum log level is set accordingly, whereas the second one is not, but offers more flexibility through the streaming operators. Use the former if speed matters.
The macros require three pieces of information:
UHD_LOGGER_DEBUG
vs. UHD_LOGGER_INFO
.Anything that acts upon a log message is called a backend. UHD defines two by default: A logfile, and a console backend. More backends can be added by calling uhd::log::add_logger().