Java:log4j配置文件及Maven依赖
依赖:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
在classpass路径下加入log4j.properties
LOG_DIR=D:/logs/data-od
log4j.rootCategory=error,od,Console #将error错误输出到od和Console,具体输出到哪里看log4j.appender.od和log4j.appender.Console定义
log4j.appender.Console=org.apache.log4j.ConsoleAppender #输出位置为控制台
log4j.appender.Console.layout=org.apache.log4j.PatternLayout #输出格式
log4j.category.com.data.od=error,od #log4j.category.包名 : 将com.data.od包下的error错误输出到od,具体输出到哪里看log4j.appender.od定义
log4j.additivity.com.hsf=false #com.hsf包下的日志不输出到控制台
log4j.category.org.springframework = error,Spring
log4j.additivity.org.springframework =false
log4j.category.com.hsf = error,HSF
log4j.additivity.com.hsf =false
log4j.appender.od=org.apache.log4j.RollingFileAppender
log4j.appender.od.File=${LOG_DIR}/data-od.log
log4j.appender.od.MaxFileSize=5000000
log4j.appender.od.layout=org.apache.log4j.PatternLayout
log4j.appender.od.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %-5p %c %x - %m%n
log4j.appender.Spring=org.apache.log4j.RollingFileAppender
log4j.appender.Spring.File=${LOG_DIR}/spring.log
log4j.appender.Spring.MaxFileSize=5000000
log4j.appender.Spring.layout=org.apache.log4j.PatternLayout
log4j.appender.Spring.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %-5p %c %x - %m%n
log4j.appender.HSF=org.apache.log4j.RollingFileAppender
log4j.appender.HSF.File=${LOG_DIR}/hsf.log
log4j.appender.HSF.MaxFileSize=5000000
log4j.appender.HSF.layout=org.apache.log4j.PatternLayout
log4j.appender.HSF.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %-5p %c %x - %m%n
# SqlMap logging configuration.
#log4j.logger.com.ibatis=DEBUG
#log4j.category.com.ibatis.common.jdbc.SimpleDataSource=DEBUG,ibatis
#log4j.category.com.ibatis.common.jdbc.ScriptRunner=DEBUG,ibatis
#log4j.category.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG,ibatis
log4j.category.java.sql=DEBUG, sql
log4j.additivity.java.sql=false
log4j.appender.sql=org.apache.log4j.RollingFileAppender
log4j.appender.sql.File=${LOG_DIR}/sql.log
log4j.appender.sql.MaxFileSize=5000000
log4j.appender.sql.layout=org.apache.log4j.PatternLayout
log4j.appender.sql.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %-5p %c %x - %m%n