"maxFileSize must be specified" 对于 config.yml 使用 dropwizard

"maxFileSize must be specified" for config.yml while using dropwizard

自从我从 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;

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

自 dropwizard v0.9.0 以来,所有文件轮换策略均已使用 class FileAppenderFactory 完成。因此,尝试将 file-size-rolled 替换为 file,它应该可以工作。

此外,请确保您没有任何 0.7.1 罐子留在 class-路径中。我猜他们在附近,因为您没有收到以下错误消息。

Could not resolve type id 'file-size-rolled' into a subtype of [simple type, class io.dropwizard.logging.AppenderFactory]: known type ids = [AppenderFactory, console, file, syslog]"

如果您有兴趣,Github 上的 Pull Request

Edit - 还添加了不需要自定义 class SizeBasedRollingFileAppenderFactory 的事实不再 post dropwizard 应用中的更改 1.0.0