📄 e389. minimizing the impact of logging code.txt
字号:
It is good to add logging code to an application, but the logging code should minimize its impact on the application, especially if the logging is not enabled. In particular, if the message to be potentially logged needs to be constructed, the method call should be wrapped in a cheaper check. For example, the method call
int count = 123;
Logger logger = Logger.getLogger("com.mycompany.MyClass");
logger.finest("count: "+count);
will cause the count to be converted to a string and then concatenated to another string. This is a lot of wasted work if the message will not be logged. To avoid this overhead, use Logger.isLoggable() to check if the message would be logged before calling the logging method. For example,
if (logger.isLoggable(Level.FINEST)) {
logger.finest("count: "+count);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -