• 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" />
        <!-- test文件路径 -->
        <property name="TEST_FILE_PATH" value="D:\comp\日志管理" />
        <!-- pro文件路径 -->
        <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}.log</file>
                <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                    <!-- rollover daily -->
                    <fileNamePattern>${TEST_FILE_PATH}${file.separator}${LOG_NAME}-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
                    <!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
                    <maxHistory>7</maxHistory>
                    <maxFileSize>100MB</maxFileSize>
                    <totalSizeCap>20GB</totalSizeCap>
                </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}.log</file>
                <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                    <!-- rollover daily -->
                    <fileNamePattern>${PROD_FILE_PATH}${file.separator}${LOG_NAME}-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
                    <!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
                    <maxHistory>7</maxHistory>
                    <maxFileSize>100MB</maxFileSize>
                    <totalSizeCap>20GB</totalSizeCap>
                </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>
  • 相关阅读:
    20100720 14:14 转:BW十日谈之标准数据源
    BW会计年度期间转换出错
    SQL Server 2005 Logon Triggers 详细介绍
    作业输出文档维护
    windows 系统监视器 以及建议阀值
    linkedserver 的使用
    DAC 连接数据库需要做些什么
    SQL Server 2008新特性 Merge 详细见联机手册
    【20110406】提高数据库可用性需要注意的问题
    索引迁移
  • 原文地址:https://www.cnblogs.com/songanwei/p/9181852.html
Copyright © 2020-2023  润新知