国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

How to use log4j in java without declaring it every time it is called?
為情所困
為情所困 2017-05-17 10:04:39
0
3
726

Every time you write a new class, you must declare it as follows:

private static Logger logger = Logger.getLogger(Test.class);  

Isn’t this very troublesome? Is there any way to set the Logger to a class that can be called statically, directly call the info, error and other methods, and at the same time print out the current class, thread number and other information?

為情所困
為情所困

reply all(3)
漂亮男人

You can simply encapsulate it to achieve what you want, such as building a class to encapsulate Logger and exposing several static interfaces. As for why many codes are written as private static Logger logger = Logger.getLogger(Test.class);, it is actually mainly to improve the flexibility and accuracy of logs.

給我你的懷抱

Look at this /a/11...

漂亮男人

Statementlog是因?yàn)樗梢远x不同的logger name可以通過(guò)logger name定制自己的輸出方式, 比如level, appender...etc

If your logs are processed in the same way, you can declare it公共的靜態(tài) log 對(duì)象, 需要的地方使用該logThere will be no duplicate declarations.
For example:

import static xxx.GlobalLogs.log;

log.debug("...");
log.info("...");
//...

Of course you can also use lombok to simplify your code.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template