-
Notifications
You must be signed in to change notification settings - Fork 5
logging
DeDos provides a logging module (located in src/common/logging.h) which provides macro definitions for several provided logging levels, as well as custom log levels that can be turn on or off for individual modules or features.
The provided log levels are:
log_debug(fmt, ...) // Use not suggested. Use log(LVL, fmt, ...) instead
log_info(fmt, ...)
log_warn(fmt, ...)
log_error(fmt, ...)
log_critical(fmt, ...)These log levels should be used for information which is both useful and relatively rare. With the standard set of log levels enabled, the developer should try to avoid having the terminal flooded with messages.
For information which is useful to have, but is largely for the purposes of debugging, use the provided macro:
log(LVL, fmt, ...)The log() function allows you to define custom log levels with no extra work on the developer's side. Simply call
log(LOG_MY_LOG_LEVEL, "It's %s, it's %s, it's %s", "big", "heavy", "wood");If the preprocessor definitions LOG_CUSTOM and LOG_MY_LOG_LEVEL are defined, the line will be output to stderr as:
<thread_no>:my/file/path.c:<line_no>:fn_name(): LOG_MY_LOG_LEVEL: It's big, it's heavy, it's wood
If LOG_CUSTOM or LOG_MY_LOG_LEVEL is not defined, the line will be optimized out (as long as the optimization level of compilation is sufficiently high).
Note: MY_LOG_LEVEL can be replaced with any string.
The runtime's makefile (runtime.mk) contains a list of the enabled log levels. It looks as follows:
LOGS = \
INFO \
ERROR \
WARN \
CRITICAL \
CUSTOM \
#YOUR_LOG_LEVEL_HERE
NO_LOGS = # See "Enabling all log levels" belowAdd your MY_LOG_LEVEL to the list of logs to have it be automatically included in the preprocessor definitions.
There is an additional preprocessor definition, LOG_ALL, which can be turned on by adding the level ALL to the LOGS list in the makefile. If LOG_ALL is present, every custom log level will be printed. This can be useful for extreme debugging.
In the case in which you want all log levels except some specific ones, add the undesirable log levels to the NO_LOGS list in the makefile. The NO_LOGS list supercedes the LOGS list, and will cause the corresponding log levels to be compiled out.