You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In other logging libraries, there are preprocessor macros that make use of an if-expression to make sure the log line expressions are only evaluated if the associated log level is enabled. Example (using iostreams, but fmlib would work as well):
LOG_TRACE("Test " << (4+i) << " " << call_a_slow_function() << " 123");
#define LOG_TRACE(LOGLINE) \
do {
if (current_global_log_level >= TRACE) {
std::cerr << LOGLINE;
}
} while (0)
The effect of such a macro is that the expressions within LOGLINE are only evaluated if (current_global_log_level >= TRACE) holds true. So, in other words, (4+1) is not evaluated and call_a_slow_function() is not called if the log level is not at TRACE. This is very useful, since it makes a lot of logging effectively very near zero cost operation (only the integer comparison for the log level check is done always), while still being able to function with log levels that are adjustable at run-time (current_global_log_level could be some internal integer that can be set via some sort of public set_global_log_level() function).
Unfortunately, this is not possible with spdlog, from what it seems. Compile-time macros like SPDLOG_TRACE() use preprocessor macros for enabling/disabling log calls, and do not check the runtime log levels. And the regular logging calls are always evaluated; the decision whether or not to actually log something is done internally.
Or is there a way to achieve what I am describing?
The text was updated successfully, but these errors were encountered:
In other logging libraries, there are preprocessor macros that make use of an if-expression to make sure the log line expressions are only evaluated if the associated log level is enabled. Example (using iostreams, but fmlib would work as well):
The effect of such a macro is that the expressions within LOGLINE are only evaluated if (current_global_log_level >= TRACE) holds true. So, in other words, (4+1) is not evaluated and call_a_slow_function() is not called if the log level is not at TRACE. This is very useful, since it makes a lot of logging effectively very near zero cost operation (only the integer comparison for the log level check is done always), while still being able to function with log levels that are adjustable at run-time (current_global_log_level could be some internal integer that can be set via some sort of public set_global_log_level() function).
Unfortunately, this is not possible with spdlog, from what it seems. Compile-time macros like SPDLOG_TRACE() use preprocessor macros for enabling/disabling log calls, and do not check the runtime log levels. And the regular logging calls are always evaluated; the decision whether or not to actually log something is done internally.
Or is there a way to achieve what I am describing?
The text was updated successfully, but these errors were encountered: