zoukankan      html  css  js  c++  java
  • logback 三

    一.LoggerFactory.gerLogger()使用:
      private Logger vitalLogger= LoggerFactory.getLogger("vitalRequest");
      如果为字符串 则需要在logback.xml中配置
      <logger name="vitalRequest" level="INFO" additivity="false">
       <appender-ref ref="vitalRequestAppender"/>
      </logger>
      其中vitalRequestAppender则为上面所配置的Appender
    具体如下
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    
        <property name="LOG_HOME" value="${CATALINA_BASE}/logs"/>
    
        <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>INFO</level>
            </filter>
            <encoder>
                <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}]WTraceId[%X{wtraceid}] %5p %logger{0}:%L] %msg%n</pattern>
            </encoder>
        </appender>
    
        <appender name="accessAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${LOG_HOME}/request.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${LOG_HOME}/request.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
            </rollingPolicy>
            <encoder>
                <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}]WTraceId[%X{wtraceid}] %5p %logger{0}:%L] %msg%n</pattern>
            </encoder>
        </appender>
    
        <appender name="requestAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${LOG_HOME}/cvs.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${LOG_HOME}/cvs.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
                <MaxHistory>15</MaxHistory>
            </rollingPolicy>
            <encoder>
                <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}]WTraceId[%X{wtraceid}] %5p %logger{0}:%L] %msg%n</pattern>
            </encoder>
        </appender>
    
        <!--关键信息导出文件-->
        <appender name="vitalRequestAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${LOG_HOME}/vitalRequest.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${LOG_HOME}/vitalRequest.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
            </rollingPolicy>
            <encoder>
                <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}]WTraceId[%X{wtraceid}] %5p %logger{0}:%L] %msg%n</pattern>
            </encoder>
        </appender>
    
        <logger name="accessDataLog" level="INFO" additivity="false">
            <appender-ref ref="accessAppender"/>
        </logger>
    
    
        <logger name="com.wormpex.inf.wmq.rabbit.consumer.RapidMQMessageListenerAdapter" level="DEBUG" additivity="false">
            <appender-ref ref="console" />
        </logger>
    
        <logger name="vitalRequest" level="INFO" additivity="false">
            <appender-ref ref="vitalRequestAppender"/>
        </logger>
    
        <logger name="com.wormpex.fd.trace.handler.LoggerAlarmHandler" level="ERROR" additivity="false" />
    
        <root level="INFO">
            <appender-ref ref="console"/>
            <appender-ref ref="requestAppender"/>
        </root>
    
    </configuration>

    如logback前两个文章所说 层级配置,及向指定文件输出日志内容。



  • 相关阅读:
    底层因为接受到操作系统信号而停止的解决
    C语言判断文件是否存在
    Linux磁盘设备文件(sda,sdb,sdc…)变化问题
    linux mysql 数据目录文件夹移动及所遇到的问题
    Linux Mysql如何移动MySQL数据库目录位置
    Linux 磁盘挂载和mount共享
    提高VS2010/VS2012编译速度
    C++[类设计] ini配置文件读写类config
    WIN32读写INI文件方法
    MS509Team----------------Cknife
  • 原文地址:https://www.cnblogs.com/KingIceMou/p/8024739.html
Copyright © 2011-2022 走看看