Log4j optimization

xiaoxiao2021-03-06  126

How many people will add a judgment before every debug / info with log4j? Many people may say, what is the relationship, I am running with the log level to Error when running. So, please see the following code: String Result; ......... Logger.debug ("result is" result); look at this code: String Result; ......... (Logger.Indebugenabled ()) {logger.debug ("Result is" result);} Set the log level to Error, run the result again? No! ! Is there a difference between the performance of the program? Different !!! Because what? Although the first code does not produce a log output, the string variable in Debug () is instantiated, is it? This is why many people complain that log4j takes a lot of CPU time, especially when it is a large cycle. Hurry and add such judgment in your program.

转载请注明原文地址:https://www.9cbs.com/read-99727.html

New Post(0)