1. 程式人生 > >引入Log4j

引入Log4j

war console warn uic cat rop odi fatal pen

1. pom文件添加依賴

<!-- log start -->
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <!-- log end -->

2. 添加log4j.properties文件

# DEBUG,INFO,WARN,ERROR,FATAL
LOG_LEVEL=DEBUG

log4j.rootLogger=${LOG_LEVEL},CONSOLE,FILE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Encoding=utf-8
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#log4j.appender.CONSOLE.layout.ConversionPattern
=[%-5p] %d{yyyy-MM-dd HH:mm:ss} %C{8}@(%F:%L):%m%n log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} %C{1}@(%F:%L):%m%n log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender log4j.appender.FILE.File=${catalina.base}/logs/quick4j.log log4j.appender.FILE.Encoding=utf-8
log4j.appender.FILE.DatePattern=.yyyy-MM-dd log4j.appender.FILE.layout=org.apache.log4j.PatternLayout #log4j.appender.FILE.layout=org.apache.log4j.HTMLLayout log4j.appender.FILE.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH\:mm\:ss} %C{8}@(%F\:%L)\:%m%n

引入Log4j