简体   繁体   中英

Slf4j LOGGER usage

Can anyone throw some light on the clear usage of different levels of LOGGER viz LOGGER.info() LOGGER.trace(), LOGGER.error() and LOGGER.debug().

Pls note its not about configuration, but its about when to use info() and when not to use etc.

I tend to use them like this:

TRACE: Mark where something has executed, like the start of a method. I'm usually not interested logging any information other than "this line executed". Usually turned off in both development and production (to prevent logging large amounts of output) but turned on if I'm diagnosing a defect that is particularly difficult to locate.

DEBUG: Output detailed information about variable state to the logs. After development is complete I turn up the logging level to INFO so these are not output to the logs. If I'm debugging a production problem, I sometimes put the logging level back down to DEBUG to start seeing this output again and assist in diagnosing the problem.

INFO: Output small amounts of important information, such as when a critical method is invoked. Sometimes I leave this on in production, sometimes not.

WARN: Output information about unexpected application state or error that does not prevent the application from continuing to execute. Usually turned on in production.

ERROR: Output information about unexpected application state or error that prevents an operation from completing execution. Always turned on in production.

You said that you aren't looking for help on configuration, but this other slf4j question might be of interest to you anyway.

These are common names for logger frameworks. Usually it's something like this:

  • debug is for the developer and usually disabled in production use
  • trace is even finer than debug, logging eg method calls and returns

The rest should be self explanatory. Of course it is not always clear cut what event should be logged in what level.

You should have a look at the information in the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM