log4j
log4j
pxm.xml导入
<!--slf4j+log4j-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
log4j.properties
log4j.rootLogger=engine,Console,info
#log4j.Logger=debug
log4j.logger.com.springframework=INFO
log4j.logger.org.apache.ibatis=ERROR
log4j.logger.com.ibatis=ERROR
log4j.logger.java.sql=ERROR
log4j.logger.org.freemarker=ERROR
log4j.logger.freemarker.beans=WARN
log4j.logger.freemarker=ERROR
log4j.appender.db = com.tedu.base.common.error.MyJDBCAppender
log4j.appender.db.BufferSize=1
log4j.appender.db.driver=com.mysql.jdbc.Driver
log4j.appender.db.URL=${mysql.jdbc.url}
log4j.appender.db.user=${mysql.jdbc.username}
log4j.appender.db.password=${mysql.jdbc.password}
log4j.appender.db.sql=insert into WDZLOG (`createDate`, `logContent`, `logLevel`, `logClass`,`ip`,`port`) VALUES ('%d{yyyy-MM-dd HH:mm:ss}', '%m', '%p', '%X{logClass}', '%X{ip}', '%X{port}')
log4j.appender.db.layout=org.apache.log4j.PatternLayout
log4j.appender.db.Threshold=error
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.encoding=uft-8
log4j.appender.Console.Target=System.out
log4j.appender.Console.Threshold=info
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %p => %m %n
#log4j.appender.Console.layout.ConversionPattern=[%d{yy/MM/dd HH\:mm\:ss\:SSS}] [%t]
log4j.appender.Console.com.googlecode.Threshold=ERROR
log4j.appender.info=org.apache.log4j.DailyRollingFileAppender
log4j.appender.info.Append=true
log4j.appender.info.layout=org.apache.log4j.PatternLayout
log4j.appender.info.layout.ConversionPattern=[ts-engine] %d{yyyy-MM-dd HH\:mm\:ss,SSS} %p => %m %n
log4j.appender.info.datePattern='.'yyyy-MM-dd'.log'
log4j.appender.info.Threshold = debug
log4j.appender.info.append=true
log4j.appender.info.File=${catalina.home}/logs/info.log
log4j.appender.engine=org.apache.log4j.DailyRollingFileAppender
log4j.appender.engine.Append=true
log4j.appender.engine.layout=org.apache.log4j.PatternLayout
log4j.appender.engine.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss\:SSS}] %m%n
log4j.appender.engine.datePattern='.'yyyy-MM-dd'.log'
log4j.appender.engine.Threshold = DEBUG
log4j.appender.engine.append=true
log4j.appender.engine.File=${catalina.home}/logs/formengine.log
log4j.appender.engine.Encoding=UTF-8
配置mybatis-config.xml
<settings>
<setting name="logImpl" value="LOG4J" />
</settings>
使用
private static final Logger logger = org.apache.log4j.Logger.getLogger(User.class);
@RequestMapping("/login")
public String login() {
logger.debug("开始打印日志==========");
logger.info("info================");
logger.debug("info================");
System.out.println("syso================");
return "login";
}