一.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前两个文章所说 层级配置,及向指定文件输出日志内容。