欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

logback 常用配置及说明

程序员文章站 2022-03-07 10:24:55
...

 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<property name="LOG_HOME" value="/data/logs"/>

    <!--输出到控制台-->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <!--对日志进行格式化-->
		<encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-4relative %-5level [%thread] %logger{56}.%method:%L - %msg%n</pattern>
            <charset>utf-8</charset>
        </encoder>
    </appender>
	
	<!-- 输出到文件 -->
	<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
            <maxHistory>30</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>20MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %-4relative %-5level [%thread] %logger{56}.%method:%L - %msg%n</pattern>
        </encoder>
    </appender>
    

	<!-- name 用来指定受此loger约束的某一个包或者具体的某一个类 -->
	<!-- additivity 是否向上级loger传递打印信息。默认是true -->
	<!-- level 用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF -->
	<logger name="com.alibaba" 			level="WARN"/>
	<logger name="org.springframework" 	level="INFO"/>
	<logger name="org.apache" 			level="WARN"/>
	<logger name="org.mybatis" 			level="WARN"/>
	<logger name="com.netflix" 			level="WARN"/>
	<logger name="io.netty" 			level="WARN"/>
	
	<!-- root 默认的级别是 INFO-->
	<root level="INFO">
		<appender-ref ref="FILE" />
		<appender-ref ref="CONSOLE" />
	</root>

</configuration>

 

 

相关标签: logback