src/main/resources/log4j.properties
内容示例:
### set log levels and 3 appenders ###
# Trace, Debug, Info, Warn, Error, Fatal#log4j.rootLogger = DEBUG, stdout, D, E### stdout ###log4j.appender.stdout = org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target = System.outlog4j.appender.stdout.layout = org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t] [%p] [%F:%L] %m%n### D ###log4j.appender.D = org.apache.log4j.DailyRollingFileAppenderlog4j.appender.D.File = debug.log## Debug file name ##log4j.appender.D.Append = truelog4j.appender.D.Threshold = DEBUG ## 输出DEBUG级别以上的日志log4j.appender.D.layout = org.apache.log4j.PatternLayoutlog4j.appender.D.layout.ConversionPattern= %-d{yyyy-MM-dd HH:mm:ss} [%t] [%p] [%F:%L] %m%n### E ###log4j.appender.E = org.apache.log4j.DailyRollingFileAppenderlog4j.appender.E.File = error.log log4j.appender.E.Append = truelog4j.appender.E.Threshold = ERROR ## 只输出ERROR级别以上的日志!!!log4j.appender.E.layout = org.apache.log4j.PatternLayoutlog4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t] [%p] [%F:%L] %m%npom.xml
<project
......
<dependencies>
......
<dependency>
<groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>......
</dependencies>
<build>
......
<resources>
......
<resource>
<!-- auto copy to target/classes e.g. log4j.properties -->
<directory>src/main/resources</directory>
</resource> </resources> </build></project>