I'm using the org.jboss.logging.Logger class, and seem to have come across an incongruity. When I have an error or warning, I simply have to use logger.error("error message")
or logger.warn("warning message")
and it will be displayed based on the settings in the jboss-log4j.xml file.
However, based on existing jboss code, this discussion, and this link, when trace is used you must first determine whether it is enabled using logger.isTraceEnabled()
. Why does it appear that I have to this for trace alone?
You don't "have to". It will work just fine without it. However, TRACE-level logging tends to to be massively verbose, and can take up a significant proportion of CPU time, even if it's ultimately not actually logged to the file. By putting the if
check around the logging statement, you avoid that overhead.
I've seen other good quality codebases do the same for DEBUG and INFO level logging also, so it's not limited to TRACE.
See the section of the log4j manual relating to peformance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With