Disable logging with log4cxx for minimal overhead
I am using log4cxx for logging. However, registration can introduce some performance overhead that I need to keep to a minimum.
How can I disable logging (at runtime or compile time) to minimize overhead - failed to remove all log statements from the code?
The documentation states that
The user should be aware of the following performance issues.
Effectiveness of logging when disabled.
When logging is completely disabled, or only for a set of levels, the cost of a log request consists of a method call plus an integer comparison. LOG4CXX_DEBUG and similar macros suppress the unnecessary expression if the query is not enabled.
But how do you turn it off completely? Is this the minimum overhead that can be achieved?
source to share
If you really want to disable all logging at compile time, just override the log4cxx macros and nothing.
#define LOG4CXX_TRACE(logger, expression)
#define LOG4CXX_DEBUG(logger, expression)
#define LOG4CXX_INFO(logger, expression)
#define LOG4CXX_WARN(logger, expression)
#define LOG4CXX_ERROR(logger, expression)
#define LOG4CXX_FATAL(logger, expression)
Zero overhead. For the execution case, you always have to take on some cost. With a quick glance, I'm actually making the overhead a little more than their documentation says, usually involving an additional virtual method call. This is essentially the minimum overhead associated with using this library, although you can get some very small improvements using link time optimizations, etc. to remove the overhead of a method call.
source to share