logback 根据不同业务打印日志到不同的文件

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
	<appender name="mainServer_Error"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<!-- <file>/opt/fanqizha_tomcat/python/logs/antifraud_Error.log</file> -->

		<file>E:/logs/antifraud_Error.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<maxHistory>60</maxHistory>
			<fileNamePattern>logs/antifraud_Error_%d{yyyy-MM-dd}_%i.log
			</fileNamePattern>

			<timeBasedFileNamingAndTriggeringPolicy
				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>100MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<charset>UTF-8</charset>
			<immediateFlush>true</immediateFlush>
			<pattern>[%level][%d{yyyy-MM-dd}%d{HH:mm:ss:SSS}][%thread][%logger{40}]-
				%msg%n</pattern>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印ERROR日志 -->
			<level>ERROR</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
	</appender>

	<appender name="mainServer"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>E:/logs/antifraud.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<maxHistory>60</maxHistory>
			<fileNamePattern>logs/antifraud_%d{yyyy-MM-dd}_%i.log
			</fileNamePattern>

			<timeBasedFileNamingAndTriggeringPolicy
				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>100MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<charset>UTF-8</charset>
			<immediateFlush>true</immediateFlush>
			<pattern>[%level][%d{yyyy-MM-dd}%d{HH:mm:ss:SSS}][%thread][%logger{40}]-
				%msg%n</pattern>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> --><!-- 只打印INFO日志 -->
			<level>DEBUG</level>
			<!-- <level>INFO</level> -->
			<!-- <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> -->
		</filter>
	</appender>


	<appender name="serviceAppender"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>E:/logs/service.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<maxHistory>60</maxHistory>
			<fileNamePattern>logs/service_%d{yyyy-MM-dd}_%i.log
			</fileNamePattern>

			<timeBasedFileNamingAndTriggeringPolicy
				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>100MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<charset>UTF-8</charset>
			<immediateFlush>true</immediateFlush>
			<pattern>%msg%n</pattern>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> --><!-- 只打印INFO日志 -->
			<!-- <level>DEBUG</level> -->
			<level>DEBUG</level>
			<!-- <onMatch>DENY</onMatch> <onMismatch>ACCEPT</onMismatch> -->
			<!-- <level>INFO</level> -->
			<!-- <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> -->
		</filter>
	</appender>

	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>[%level][%d{yyyy-MM-dd}
				%d{HH:mm:ss:SSS}][%thread][%logger{40}]- %msg%n</pattern>
		</encoder>
	</appender>
	<appender name="asyncMain" class="ch.qos.logback.classic.AsyncAppender">
		<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
		<discardingThreshold>0</discardingThreshold>
		<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
		<queueSize>512</queueSize>
		<!-- 添加附加的appender,最多只能添加一个 -->
		<appender-ref ref="mainServer" />
	</appender>

	<logger name="com.geo.antifraud.core.mapper" level="DEBUG" />

	<logger name="com.geo.antifraud.core.controller.LoggerRecordUtil"
		level="DEBUG" additivity="false">
		<appender-ref ref="serviceAppender" />
		<appender-ref ref="mainServer_Error" />
	</logger>
	<root level="INFO">
		<appender-ref ref="mainServer_Error" />
		<!-- <appender-ref ref="mainServer"/> -->
		<!-- <appender-ref ref="serviceAppender" /> -->
		<appender-ref ref="asyncMain" />
		<appender-ref ref="console" />
	</root>
</configuration>  

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值