log4j.properties
log4j.rootLogger=debug,common
log4j.logger.com.server.Server=debug,A1
log4j.logger.com.server.ServerImpl=info,A2
log4j.logger.com.dao=error,A3
log4j.appender.common=org.apache.log4j.DailyRollingFileAppender
log4j.appender.common.Append=true
log4j.appender.common.ImmediateFlush=true
log4j.appender.common.DatePattern='.'yyyy-MM-dd
log4j.appender.common.File=logs/common.log
log4j.appender.common.layout=org.apache.log4j.PatternLayout
log4j.appender.common.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%l] [%p] - %m%n
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.Append=true
log4j.appender.A1.ImmediateFlush=true
log4j.appender.A1.DatePattern='.'yyyy-MM-dd
log4j.appender.A1.File=logs/A1.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%l] [%p] - %m%n
#log4j.additivity.com.server.Server=false
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.Append=true
log4j.appender.A2.ImmediateFlush=true
log4j.appender.A2.DatePattern='.'yyyy-MM-dd
log4j.appender.A2.File=logs/A2.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%l] [%p] - %m%n
log4j.additivity.com.server.ServerImpl=false
log4j.appender.A3=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A3.Append=true
log4j.appender.A3.ImmediateFlush=true
log4j.appender.A3.DatePattern='.'yyyy-MM-dd
log4j.appender.A3.File=logs/A3.log
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%l] [%p] - %m%n
log4j.additivity.com.dao=false
common.log
显示日志级别:debug,除了log4j.additivity.*=false的日志
2017-01-05 16:39:48,302 [com.server.Server.server1(Server.java:11)] [INFO] - Server info
2017-01-05 16:39:48,303 [com.server.Server.server1(Server.java:12)] [ERROR] - Server error
2017-01-05 16:39:48,303 [com.server.Server.server1(Server.java:13)] [DEBUG] - Server debug
2017-01-05 16:39:48,303 [com.Test.main(Test.java:14)] [INFO] - Test info
2017-01-05 16:39:48,303 [com.Test.main(Test.java:15)] [ERROR] - Test error
2017-01-05 16:39:48,304 [com.Test.main(Test.java:16)] [DEBUG] - Test debug
2017-01-05 16:39:48,305 [com.server.ServerT.serverT1(ServerT.java:9)] [INFO] - ServerT1 info
2017-01-05 16:39:48,305 [com.server.ServerT.serverT1(ServerT.java:10)] [ERROR] - ServerT1 error
2017-01-05 16:39:48,305 [com.server.ServerT.serverT1(ServerT.java:11)] [DEBUG] - ServerT1 debug
A1.log
显示日志级别:debug,显示com.server.Server方法中日志,该日志也在common.log中显示
2017-01-05 16:39:48,302 [com.server.Server.server1(Server.java:11)] [INFO] - Server info
2017-01-05 16:39:48,303 [com.server.Server.server1(Server.java:12)] [ERROR] - Server error
2017-01-05 16:39:48,303 [com.server.Server.server1(Server.java:13)] [DEBUG] - Server debug
A2.log
显示日志级别:info,显示com.server.ServerImpl方法中日志,该日志只在这里显示
2017-01-05 16:39:48,301 [com.server.ServerImpl.serverImpl_method1(ServerImpl.java:13)] [INFO] - ServerImpl info
2017-01-05 16:39:48,302 [com.server.ServerImpl.serverImpl_method1(ServerImpl.java:14)] [ERROR] - ServerImpl error
A3.log
显示日志级别:error,显示com.dao包下的日志,该日志只在这里显示
2017-01-05 16:39:48,298 [com.dao.DaoImpl.DaoImpl_method1(DaoImpl.java:10)] [ERROR] - DaoImpl error
2017-01-05 16:39:48,301 [com.dao.Dao.dao1(Dao.java:12)] [ERROR] - Dao error
源码下载地址:http://download.csdn.net/detail/adam_zs/9729804