log4j two print log configurations common-logging and

Familiarize yourself with the overall knowledge and process first, and then analyze it in detail (especially for unfamiliar problems) (if you are unfamiliar, analyze the appearance of the problem first, check it, and avoid wrong positioning due to unfamiliarity)

Version problem, 1 can't find the class, method 2, the effect is different when used together, although it is not wrong

Additional lib needs to be added to the compilation directory

 

Mixed 2 so the printing is inconsistent (both commons-logging and logback and slf4j are used)

 

way 1

 

 

1,commons-logging.jar ,log4j ,slf4j-log4j12 1.6,slf4j-api

 

2. Configuration file

Configure console printing, file printing, and print log levels. The log level should be well controlled. At least if debug is used for info, it will be used due to log printing.

Web page requests slow down

 

E.g:

 

 

When using Struts2 tags, the eclipse console prints a lot of mime-mapping things 

As shown above, a large amount of output information is written by feemarker and OGNL, and these log levels are DEBUG level, which will continuously print the content of web.xml

 

 

 

 

3. Print where needed in the project

 

common adapter

private static Log logger = LogFactory.getLog(LogTest.class);

        logger.debug("I am debug information");

 

log4j print

 

public static final Logger logger = Logger.getLogger(UserDao.class);

logger.debug("I am debug information");

 

 

After configuration, the two printing levels are the same, unless logback and slf4j are mixed, resulting in inconsistent log4j printing and common (level control is invalid)

 

 

 

way 2

Introduction to the use of logback and slf4j chapter1

 

http://blog.csdn.net/cw_hello1/article/details/51784736

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326275928&siteId=291194637