【问题标题】:"maxFileSize must be specified" for config.yml while using dropwizard使用 dropwizard 时为 config.yml “必须指定 maxFileSize”
【发布时间】:2016-09-06 06:46:07
【问题描述】:

自从我从 dropwizard-core 0.7.1 迁移到 1.0.0 如下 -

/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java
/Users/xyz/GitHub/test-service/config/next/config.yml has an error:
  * when archivedLogFilenamePattern contains %i, maxFileSize must be specified

问题是即使我对 config.yml 进行了相应的更改并成功编译了项目。仍然在尝试运行该项目时,我遇到了同样的错误。

config.yml

server:
  applicationConnectors:
    - type: http
      port: 8180
  adminConnectors:
    - type: http
      port: 8181
  requestLog:
      appenders:
        - type: file-size-rolled
          currentLogFilename: /var/log/test-service/access.log
          threshold: ALL
          archive: true
          archivedLogFilenamePattern: /var/log/test-service/access.%i.log.gz
          maxFileSize: 50MB
          archivedFileCount: 10
          timeZone: IST
logging:
    level: INFO
    loggers:
      io.dropwizard: INFO
    appenders:
      - type: console
        threshold: ALL
        timeZone: IST
        target: stdout
      - type: file-size-rolled
        threshold: ALL
        currentLogFilename: /var/log/test-document-service/test-service.log
        threshold: ALL
        archive: true
        archivedLogFilenamePattern: /var/log/test-service/test-service-%i.log.gz
        maxFileSize: 50MB
        archivedFileCount: 5
        timeZone: IST

如果需要,file-size-rolled 定义如下 -

@JsonTypeName("file-size-rolled")
public class SizeBasedRollingFileAppenderFactory extends FileAppenderFactory {
    public static final Size DEFAULT_MAX_FILE_SIZE_STR = Size.parse("50MB") ;

    @NotNull
    @JsonProperty
    Size maxFileSize = DEFAULT_MAX_FILE_SIZE_STR;

我在这里遗漏了哪些与版本升级相关的更改?

【问题讨论】:

    标签: java yaml dropwizard rollingfileappender fileappender


    【解决方案1】:

    从 dropwizard v0.9.0 开始,所有文件轮换策略都使用类 FileAppenderFactory 完成。因此,尝试用file 替换file-size-rolled,它应该可以工作。

    此外,请确保您没有任何 0.7.1 jar 存在于类路径中。我猜他们就在附近,因为您没有收到以下错误消息。

    无法将类型 id 'file-size-rolled' 解析为 [simple 类型,类 io.dropwizard.logging.AppenderFactory]:已知类型 ids = [AppenderFactory、控制台、文件、系统日志]"

    Github 上的Pull Request,以防你感兴趣。

    编辑 - 此外,在 1.0.0 中发布 dropwizard 应用程序中的更改后,将不再需要自定义类 SizeBasedRollingFileAppenderFactory

    【讨论】:

      猜你喜欢
      • 2018-11-19
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多