脚手架搭建之 日志打印

1.yml
logging:
  config: classpath:logback-spring.xml
log:
  level:
    root: info
    my: debug
  file: logs/admin-server.log
  maxsize: 30MB
logback-spring.xml
<?xml version='1.0' encoding='UTF-8'?>
<configuration>
	<springProperty name="logFile" source="log.file" />
	<springProperty name="rootlevel" source="log.level.root" />
	<springProperty name="mylevel" source="log.level.my" />
	<springProperty name="maxFileSize" source="log.maxsize" />

	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>%d [%thread] %-5level %logger{50} -[%file:%line]- %msg%n
			</pattern>
			<charset>UTF-8</charset>
		</encoder>
	</appender>

	<appender name="adminLog"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${logFile}</file>
		<encoder>
			<pattern>%d [%thread] %-5level -[%file:%line]- %msg%n
			</pattern>
			<charset>UTF-8</charset>
		</encoder>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${logFile}.%d{yyyy-MM-dd}.%i</fileNamePattern>
			<maxFileSize>${maxFileSize}</maxFileSize>
		</rollingPolicy>
	</appender>

	<appender name="errorLog"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${logFile}.error</file>
		<encoder>
			<pattern>%d [%thread] %-5level %logger{36} -[%file:%line]- %msg%n
			</pattern>
			<charset>UTF-8</charset>
		</encoder>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${logFile}.error.%d{yyyy-MM-dd}.%i</fileNamePattern>
			<maxFileSize>${maxFileSize}</maxFileSize>
		</rollingPolicy>
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>error</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
	</appender>

	<appender name="sqlLog"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${logFile}.sql</file>
		<encoder>
			<pattern>%d [%thread] %msg%n
			</pattern>
			<charset>UTF-8</charset>
		</encoder>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${logFile}.sql.%d{yyyy-MM-dd}.%i</fileNamePattern>
			<maxFileSize>${maxFileSize}</maxFileSize>
		</rollingPolicy>
	</appender>

	<logger name="adminLogger" level="${mylevel}" additivity="true">
		<appender-ref ref="adminLog" />
	</logger>

	<logger name="com.zhangmeng.mystyle.dao" level="DEBUG" additivity="true">
		<appender-ref ref="sqlLog" />
	</logger>

	<logger name="org.springframework.scheduling.quartz" level="error" additivity="true">
		<appender-ref ref="adminLog" />
	</logger>

	<root level="${rootlevel}">
		<appender-ref ref="STDOUT" />
		<appender-ref ref="errorLog" />
	</root>

</configuration>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值