[英]Use of logger in Utility classes of java
i am just wondering 'bout use of Logger API in Utility classes while writing java code. 我只是想知道在编写java代码时,在实用程序类中使用Logger API。 we can always use logger where we will be using our utility class to log a proper message BUT what i want to ask is--
我们总是可以使用logger,我们将使用我们的实用程序类来记录正确的消息但是我想问的是 -
Is it a good practice to use Logger in utility classes? 在实用程序类中使用Logger是一个好习惯吗?
I assume you are writing your own *Util code. 我假设您正在编写自己的* Util代码。
Personally I avoid using Logger in utility classes, because of the "noise" in the log files. 我个人避免在实用程序类中使用Logger,因为日志文件中存在“噪音”。 If your utility class is well tested, you may remove the log statements.
如果您的实用程序类经过了充分测试,则可以删除日志语句。
Just remember to only log, and not perform any business logic in the log statement (whether utility class or not). 只记得只记录,而不是在日志语句中执行任何业务逻辑(无论是否为实用程序类)。
Eg I saw below in one of my projects, and this is not good practice. 我在下面的一个项目中看到过,这不是一个好习惯。
log.info("Added = " + list.add("someString"));
It is a great Idea to use java.util.logging.Logger
in all utility classes. 在所有实用程序类中使用
java.util.logging.Logger
是一个很好的主意。 The most Java logging frameworks are able to collect Logs from this logger and you won't need to bundle any libraries, because it comes along with the jre. 大多数Java日志记录框架都能够从此记录器收集日志,您不需要捆绑任何库,因为它随jre一起提供。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.