将配置备份到Java项目中

时间:2016-08-02 07:33:27

标签: java linux tomcat logging logback

我正在使用logback将我的所有INFO保存到日志文件中,并且每天我都想将此文件保存在特定文件夹archived中 这就是我配置它的方式:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
            </Pattern>
        </layout>
    </appender>

    <appender name="FILE-AUDIT"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${CATALINA_HOME}/logs/DartFleetViewer.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss} - %msg%n
            </Pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>${CATALINA_HOME}/logs/archived/DartFleetViewer.%d{yyyy-MM-dd}.%i.log
                        </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>30</maxHistory>
        </rollingPolicy>

    </appender>

    <!-- <appender name="FILE-ERROR"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${DEV_HOME}/error.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss} - %msg%n
            </Pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            rollover daily
            <fileNamePattern>${DEV_HOME}/archived/error.%d{yyyy-MM-dd}.%i.log
                        </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>

    </appender> -->

    <!-- Send logs to both console and file audit -->
    <root level="info">
        <appender-ref ref="FILE-AUDIT" />
        <appender-ref ref="STDOUT" />
    </root>

    <!-- <root level="error">
        <appender-ref ref="FILE-ERROR" />
    </root> -->

</configuration>

奇怪的是我在我的文件夹中找到了这个

enter image description here

几乎所有文件都是空的或代码行很少,例如我昨天没有发现任何内容,在最后一个文件中我只找到

2016-08-02 02:18:06 - SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS
2016-08-02 05:18:06 - SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS
2016-08-02 08:18:06 - SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS

这是关于今天而不是昨天的信息。 此外,昨天我有一些错误,警告和大量的信息日志。 你在我的配置文件中看到了一些错误吗?

更新: 由于我在部署期间收到警告,因此我更改了我的注销配置以避免所有警告,并且我只使用时间回滚。它似乎有效:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
            </Pattern>
        </encoder>
    </appender>

    <appender name="FILE-AUDIT"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${CATALINA_HOME}/logs/DartFleetViewer.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>${CATALINA_HOME}/logs/archived/DartFleetViewer.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>30</maxHistory>     
            <totalSizeCap>10GB</totalSizeCap>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>
                %d{yyyy-MM-dd HH:mm:ss} - %msg%n
            </pattern>
        </encoder>
    </appender>

    <!-- Send logs to both console and file audit -->
    <root level="info">
        <appender-ref ref="FILE-AUDIT" />
        <appender-ref ref="STDOUT" />
    </root>

    <!-- <root level="error">
        <appender-ref ref="FILE-ERROR" />
    </root> -->

</configuration>

0 个答案:

没有答案