【问题标题】:spring boot logback rolling file append-er not workingspring boot logback滚动文件append-er不起作用
【发布时间】:2017-08-27 21:11:31
【问题描述】:

我正在开发一个 Spring Boot 应用程序,我正在从 Consul 中的 YML 文件中读取 logback 配置。以下是我在 YML 文件中使用的配置。

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 

现在生成了日志文件,但滚动附加程序不起作用,对此有任何帮助,当我们从 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 文件进行配置

【问题讨论】:

  • 这方面有什么帮助吗??

标签: spring-boot logback spring-boot-actuator spring-cloud-consul


【解决方案1】:

经过大量搜索,我发现 Spring Boot 尚不支持此功能。选项只有:

# 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 应该支持将滚动文件名模式提供给我们。而且它不是存档文件。

【讨论】:

    猜你喜欢
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 2018-01-27
    • 2017-05-01
    • 1970-01-01
    • 2021-11-18
    相关资源
    最近更新 更多