其他分享
首页 > 其他分享> > log4j2

log4j2

作者:互联网

 

 

如果设置级别为INFO,则优先级大于等于INFO级别(如:INFO、WARN、ERROR)的日志信息将可以被输出

log4j2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration>
    <appenders>
        <Console name="console" target="SYSTEM_OUT ">
            <PatternLayout pattern="%d{yyy MMM dd HH:mm:ss,SSS}: %p %t %c- %m%n"></PatternLayout>
        </Console>
       <RollingFile name="test" fileName="../logs/test.log" filePattern="../logs/test.log.%d{yyyyMMdd}.log">
           <PatternLayout>
               <Pattern>%d{yyy MMM dd HH:mm:ss,SSS}: %p %t %c{1}- %m%n</Pattern>
           </PatternLayout>
           <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismath="DENY"/>
           <!-- 没隔一段时间产生一个新的日志 -->
           <Policies>
               <TimeBasedTriggeringPolicy modulate="true" interval="1"/>
           </Policies>
       </RollingFile>
    </appenders>

   <Loggers>
       <logger name="cn.com" level="INFO">
           <appender-ref ref="test"/>
       </logger>
       <root level="INFO">
           <appender-ref ref="console"/>
       </root>
   </Loggers>

</Configuration>




<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-slf4j-impl</artifactId>
  <version>2.13.0</version>
</dependency>
<!--log4j到log4j2的连接包-->
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-1.2-api</artifactId>
  <version>2.13.0</version>
</dependency>
<!--非必须-->
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>2.13.0</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>2.13.0</version>
</dependency>

  

标签:INFO,logging,log4j2,apache,org,2.13,log4j
来源: https://www.cnblogs.com/xingminghui111/p/13378205.html