简体   繁体   English

禁用剂量的logger.debug是否会影响性能?

[英]Dose disabled logger.debug affects performance?

I use log4j in my application. 我在应用程序中使用log4j。 In development I use tons of logger.debug to display infomation for debugging. 在开发中,我使用大量的logger.debug来显示信息以进行调试。 I know I can make these verbose displays go away by changing the logging level in the configuration file when deployed, my questions is will this affect performance? 我知道我可以通过在部署时更改配置文件中的日志记录级别来使这些详细显示消失,我的问题是这会影响性能吗? Is it that although the debug level is disabled, the logging work is still there and dose something silently? 难道是尽管禁用了调试级别,但日志记录工作仍然存在并且静默处理了吗? Is it better to remove all the logger.debug codes in the final deploy version if performance is important? 如果性能很重要,最好删除最终部署版本中的所有logger.debug代码吗?

Modern loggers very quickly return from an inactive logging statement for this very reason 由于这个原因,现代记录器可以非常迅速地从非活动的记录语句返回

You need to be aware of the price of constructing the string to be logged. 您需要知道构造要记录的字符串的代价。 If you use slf4j as the front end, use {} to delay this until after the tests 如果您使用slf4j作为前端,请使用{}将其延迟到测试之后

Any IO operation will affect performance. 任何IO操作都会影响性能。 Even if you change logging level, each time you call log.debug , logger have to make decision to print message or not. 即使您更改日志记录级别,每次调用log.debug ,logger都必须决定是否打印消息。 However, making decision is faster than doing it with writing to file/console/something else. 但是,决策要比写入文件/控制台/其他东西更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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