Memory River

记忆河,记今日之事忆往昔之流

spring boot logback按天写日志, info和error日志分开

Rickey  \  2018-12-06 11:12:48

最简单的配置方式,只需要在resource目录下新建logback-spring.xml,

文件具体内容如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
		<layout class="ch.qos.logback.classic.PatternLayout">
			<pattern>%d - %msg%n</pattern>
		</layout>
	</appender>
	<appender name="fileInfoLog"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>ERROR</level>
			<onMatch>DENY</onMatch>
			<onMismatch>ACCEPT</onMismatch>
		</filter>
		<encoder>
			<charset>UTF-8</charset>
			<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
		</encoder>
		<!--滚动策略 -->
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!--路径 -->
			<fileNamePattern>/mr/web/logs/info.%d{yyyy-MM-dd}.log</fileNamePattern>
		</rollingPolicy>
	</appender>
	<appender name="fileErrorLog"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
		<encoder>
			<charset>UTF-8</charset>
			<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
		</encoder>
		<!--滚动策略 -->
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!--路径 -->
			<fileNamePattern>/mr/web/logs/error.%d{yyyy-MM-dd}.log</fileNamePattern>
		</rollingPolicy>
	</appender>
	<root level="info">
		<appender-ref ref="consoleLog" />
		<appender-ref ref="fileInfoLog" />
		<appender-ref ref="fileErrorLog" />
	</root>
</configuration>
标签: logback
地址: http://wchuf.com/article/adt/04d4767b4d5a42fdbf584050f7f0ffae.html
声明: 本文为原创文章,版权归本站所有,欢迎分享本文,转载请保留出处!
  272         0         0
Rickey
人,可以无傲气,但不可以无傲骨。

YOU MIGHT ALSO LIKE

0 COMMENTS
想对博主说些什么?