logback配置每天生成一个日志文件,保存30天的日志文件

xml version="1.0" encoding="UTF-8"?>
<configuration>
    
    <property name="PATTERN" value="%-12(%d{yyyy-MM-dd HH:mm:ss.SSS}) |-%-5level [%thread] %c [%L] -| %msg%n" />
    
    <property name="TEST_FILE_PATH" value="D:\\comp\\日志管理" />
    
    <property name="PROD_FILE_PATH" value="/var/log/tomcat/systemName" />
    <property name="LOG_NAME" value="systemName" />
    
    <springProfile name="dev">
        <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>${PATTERN}pattern>
            encoder>
        appender>

        
        <logger name="org.springframework.jdbc.core.JdbcTemplate" level="debug"/>
        <logger name="com.guige" level="debug" />
        <root level="info">
           <appender-ref ref="CONSOLE" />
        root>
    springProfile>
    
    
    <springProfile name="test">
        
        <appender name="TEST_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${TEST_FILE_PATH}${file.separator}${LOG_NAME}.logfile>
            <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                
                <fileNamePattern>${TEST_FILE_PATH}${file.separator}${LOG_NAME}-%d{yyyy-MM-dd}.%i.logfileNamePattern>
                
                <maxHistory>7maxHistory>
                <maxFileSize>100MBmaxFileSize>
                <totalSizeCap>20GBtotalSizeCap>
            rollingPolicy>
            <encoder>
                <pattern>
                    [%date{yyyy-MM-dd HH:mm:ss.SSS}] %X{logthreadId} %-5level %logger{80} %method  %line - %msg%n
                pattern>
            encoder>
        appender>
        <root level="info">
            <appender-ref ref="TEST_FILE" />
        root>
    springProfile>
    
    
    <springProfile name="prod">
        <appender name="PROD_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${PROD_FILE_PATH}${file.separator}${LOG_NAME}.logfile>
            <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                
                <fileNamePattern>${PROD_FILE_PATH}${file.separator}${LOG_NAME}-%d{yyyy-MM-dd}.%i.logfileNamePattern>
                
                <maxHistory>7maxHistory>
                <maxFileSize>100MBmaxFileSize>
                <totalSizeCap>20GBtotalSizeCap>
            rollingPolicy>
            <encoder>
                <pattern>
                    [%date{yyyy-MM-dd HH:mm:ss.SSS}] %X{logthreadId} %-5level %logger{80} %method  %line - %msg%n
                pattern>
            encoder>
        appender>
        <root level="warn">
            <appender-ref ref="PROD_FILE" />
        root>
    springProfile>
configuration>

 

转载于:https://www.cnblogs.com/songanwei/p/9181852.html

你可能感兴趣的:(logback配置每天生成一个日志文件,保存30天的日志文件)