Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Debug Logging

Andy Pavlo edited this page Oct 10, 2019 · 3 revisions

This page outlines:

  1. General summary of the logging support
  2. Controlling log levels and the log level default
  3. How to add logging support for a new module

Overview

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.

Log output destination

The default configuration is for all modules to send output to a common log destination. The default destination is the console.

Log levels

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.

Adding new log points

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

Adding logging for a new module

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.

Controlling log level

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);

Future

  • 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.

Troubleshooting

  1. Ensure that the logger being used has been initialized. For example,
  • init_storage_logger(); must be called, before any call to:
  • STORAGE_LOG_XXXX(...);
  1. Ensure that the log level is correct. The default, if no explicit level has been set, is INFO.