logback-spring.xml,指定日志输出到指定文件
<configuration>
<!-- 定义日志输出路径 -->
<property name="LOG_HOME" value="/path/to/log/directory" />
<!-- 定义日志格式 -->
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n" />
<!-- 控制台输出的配置 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- 文件输出的配置 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/mylog.log</file>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
<!-- 定义滚动策略 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/mylog.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<!-- 根日志器的配置 -->
<root level="info">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</configuration>
仅限制com.project.aiqicha.AiqichaTask.java中的日志输出到指定文件,且该文件与mylog.log不同,独立一个文件,名称为aiqicha.log:
<configuration>
<!-- 定义日志输出路径 -->
<property name="LOG_HOME" value="/path/to/log/directory" />
<!-- 定义日志格式 -->
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n" />
<!-- 控制台输出的配置 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- 文件输出的配置,通用日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/mylog.log</file>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
<!-- 定义滚动策略 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/mylog.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<!-- 文件输出的配置,仅限于特定类的日志 -->
<appender name="AIQICHA_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/aiqicha.log</file>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
<!-- 定义滚动策略 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/aiqicha.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<!-- 仅限制特定类的日志输出到特定文件 -->
<logger name="com.project.aiqicha.AiqichaTask" level="info">
<appender-ref ref="AIQICHA_FILE" />
</logger>
<!-- 根日志器的配置 -->
<root level="info">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</configuration>
标签:xml,mylog,log,209,PATTERN,指定,aiqicha,HOME,LOG
From: https://blog.51cto.com/u_14816966/8261619