开发者

Slf4j LOGGER usage

开发者 https://www.devze.com 2023-03-11 16:24 出处:网络
Can anyone throw some light on开发者_开发知识库 the clear usage of different levels of LOGGER viz LOGGER.info() LOGGER.trace(), LOGGER.error() and LOGGER.debug().

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 e.g. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消