Java – used to define the disadvantages of non static recorders

How do you reduce Java logging boilerplate code? It is strongly recommended not to use recorders as instance member variables I can think of two negative side effects:

However, if serialization is not required and logging with subclass names is not a problem, are there other reasons that should be avoided? I think it reduces boilerplate code, avoids copy and paste errors, and copies logger variable definitions from one class to another Even the spring framework (I believe there is a very good coding standard) uses this approach

Solution

If your logger is an instance member and not static, you must retrieve the logger every time you create a new object Although the cost may be insignificant, it is a disadvantage

From a design point of view, recorders are not attributes of objects, because they are usually meta information about the system, not business information of the system itself The recorder is not like an engine or gearbox like a car object Binding a logger to an object as a member (in most cases) makes no semantic sense

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>