0

我正在開發一個彈簧引導應用程序,我正在從Consul中的YML文件讀取logback配置。以下是我在YML文件中使用的配置。彈簧引導logback滾動文件append-er不工作

logging: 
    file: ./logs/application.log 
    pattern: 
    console: "%d %-5level %logger : %msg%n" 
    file: "%d %-4relative [%thread] %-5level %logger{35} - %msg%n" 
    level: 
    org.springframework.web: ERROR 
    com.myapp.somepackage: DEBUG 
    appenders: 
    logFormat: "%d %-4relative [%thread] %-5level %logger{35} - %msg%n" 
    currentLogFilename: ./logs/application.log 
    archivedLogFilenamePattern: ./logs/application-%d{yyyy-MM-dd}-%i.log.gz 
    archivedFileCount: 7 
    timeZone: UTC 
    maxFileSize: 30KB 
    maxHistory: 30 

現在日誌文件生成,但滾動的appender不工作,有這方面的幫助,我seraching類似就像我們進行滾動的appender弗羅馬logback.xml文件

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
    <!-- daily rollover. Make sure the path matches the one in the file element or else 
    the rollover logs are placed in the working directory. --> 
    <fileNamePattern>./logs/myapp/application_%d{yyyy-MM-dd}.%i.log</fileNamePattern> 

    <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> 
     <maxFileSize>5MB</maxFileSize> 
    </timeBasedFileNamingAndTriggeringPolicy> 
    <!-- keep 30 days' worth of history --> 
    <maxHistory>30</maxHistory> 
</rollingPolicy> 
以下的東西

同樣我需要從一個YML文件配置

+0

對此有何幫助? –

回答

0

經過大量的搜索我發現的是,這還不支持在春季啓動。選項只有:

# LOGGING 
logging.config= # Location of the logging configuration file. For instance `classpath:logback.xml` for Logback 
logging.exception-conversion-word=%wEx # Conversion word used when logging exceptions. 
logging.file= # Log file name. For instance `myapp.log` 
logging.level.*= # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 
logging.path= # Location of the log file. For instance `/var/log` 
logging.pattern.console= # Appender pattern for output to the console. Only supported with the default logback setup. 
logging.pattern.file= # Appender pattern for output to the file. Only supported with the default logback setup. 
logging.pattern.level= # Appender pattern for log level (default %5p). Only supported with the default logback setup. 
logging.register-shutdown-hook=false # Register a shutdown hook for the logging system when it is initialized. 

所以,現在不要浪費你的時間。它將在20MB之後滾動,但文件名像$ {your_file_name} .log.1等。Spring應該支持給我們滾動文件名模式。而且它不是一個存檔文件。