-
Notifications
You must be signed in to change notification settings - Fork 503
Debug Logging
This page outlines:
- General summary of the logging support
- Controlling log levels and the log level default
- How to add logging support for a new module
The logging module provides the ability to control log output, per "module". This allows log output to be controlled such that one more modules of interest generate the desired level of log output, while other modules generate little or none. Verbosity for each module can be controlled at run time.
Log calls are always invoked (even in release mode). The call will log if the log level requires it, or return.
The default configuration is for all modules to send output to a common log destination. The default destination is the console.
The following log levels are provided:
Level | Name |
---|---|
0 | TRACE |
1 | DEBUG |
2 | INFO |
3 | WARN |
4 | ERR |
6 | OFF |
The default log level setting is INFO, i.e messages of level INFO, WARN and ERR are logged. Messages of level TRACE and DEBUG are discarded. The level may be adjusted at run time at any time after the module is initialized. Each module's log level can be independently adjusted.
Log points are added using module specific macros. For example, to add a log message for the storage namespace (i.e. the storage module) use one of the storage log macros, e.g. STORAGE_LOG_INFO
By convention, each namespace has an associated logging module. To add support for a new logging module (i.e. namespace):
- In src/include/loggers, copy storage_logger.h to create a new logger header file, e.g. mymodule_logger.h. Edit the contents to reflect the name of the module.
- In terrier.cpp, main, add the initialization of the new logger. Set the default level for the new logger if desired. The level, if not initialized, is INFO.
To change the log level for a specific logger, e.g. for my_logger
my_logger->set_level(spdlog::level::debug);
For example, to enable trace logging for the optimizer_logger
, use this snippet:
optimizer_logger->set_level(spdlog::level::trace);
- The macros used for logging (e.g.,
STORAGE_LOG_TRACE
) currently always result in a check on the logger's log level. The overhead is negligible, but could be eliminated completely by defining the macros to emit no code for selected build types, e.g. release builds.
- Ensure that the logger being used has been initialized. For example,
- init_storage_logger(); must be called, before any call to:
- STORAGE_LOG_XXXX(...);
- Ensure that the log level is correct. The default, if no explicit level has been set, is INFO.
Carnegie Mellon Database Group Website