Slf4j记录器的使用
任何人都可以阐明不同级别的 LOGGER 即 LOGGER.info()、LOGGER.trace()、LOGGER.error() 和 LOGGER.debug() 的明确用法。
请注意,它不是关于配置,而是关于何时使用 info() 以及何时不使用等。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我倾向于这样使用它们:
TRACE:标记某些内容已执行的位置,例如方法的开始。我通常不感兴趣记录除“此行已执行”之外的任何信息。通常在开发和生产中关闭(以防止记录大量输出),但在我诊断特别难以定位的缺陷时打开。
DEBUG:将有关变量状态的详细信息输出到日志中。开发完成后,我将日志记录级别调高为 INFO,这样这些就不会输出到日志中。如果我正在调试生产问题,有时我会将日志记录级别重新设置为“调试”,以再次开始查看此输出并协助诊断问题。
INFO:输出少量重要信息,例如何时调用关键方法。有时我会在生产中保留此功能,有时则不会。
WARN:输出有关意外应用程序状态或错误的信息,但不会阻止应用程序继续执行。通常在生产中打开。
错误:输出有关阻止操作完成执行的意外应用程序状态或错误的信息。在生产中始终打开。
您说您不是在寻求配置方面的帮助,但是这个 其他 slf4j 问题 可能会让您感兴趣。
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:
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.