package common;import org.apache.log4j.Logger;public class MyLogger { public static Logger logger = Logger.getLogger(MyLogger.class);}
定制输出样式
# ConversionPattern # %p-->debug,info,warn,error,fatal # %t-->thread name # %c-->class name and package name # %M-->method name # %l-->happen place line(include package.class.method(line)) # %L-->line eg:(9) # %m-->message # %n-->enter. if system is windows \r\n,Unix \n # %d-->date default ISO9601, eg:%d{yyyy-MM-dd HH:mm:ss:SSS},hours HH is 24,hh is 12
web.xml
log4jConfigLocation classpath:log4j/log4j.properties org.springframework.web.util.Log4jConfigListener
log4j.properties
log4j.rootLogger=debug, stdout, logfile log4j.logger.com.ibatis=DEBUGlog4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUGlog4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUGlog4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG log4j.logger.java.sql.Connection=DEBUGlog4j.logger.java.sql.Statement=DEBUGlog4j.logger.java.sql.PreparedStatement=DEBUGlog4j.logger.java.sql.ResultSet=DEBUG log4j.logger.org.springframework=ERRORlog4j.logger.org.compass=ERROR log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.logfile=org.apache.log4j.RollingFileAppenderlog4j.appender.logfile.File=empi.log