log4j1.x maven下配置

  • src/main/resources/log4j.propertiesapache

內容示例:app

### 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.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t] [%p] [%F:%L] %m%n

### D ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = debug.log
## Debug file name ##
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
## 輸出DEBUG級別以上的日誌
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern= %-d{yyyy-MM-dd HH:mm:ss} [%t] [%p] [%F:%L] %m%n

### E ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
## 只輸出ERROR級別以上的日誌!!!
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t] [%p] [%F:%L] %m%n

ui

  • pom.xmlspa

<projectdebug

  ......
日誌

  <dependencies>xml

   ......
ci

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>

    </dependency>get

    ......
io

 </dependencies>

  <build>

   ......

    <resources>

     ......

      <resource>

         <!-- auto copy to target/classes e.g. log4j.properties -->

         <directory>src/main/resources</directory>      </resource>    </resources>  </build></project>

相關文章
相關標籤/搜索