Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it necessary to use the isTraceEnabled() function in JBoss?

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?

like image 612
josh-cain Avatar asked Mar 01 '12 16:03

josh-cain


1 Answers

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.

like image 92
skaffman Avatar answered Oct 17 '22 02:10

skaffman