1

自从我从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 进行了相应的更改并成功编译了项目。仍然在尝试运行该项目时,我遇到了同样的错误。

配置.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;

我在这里缺少与版本升级相关的哪些更改?

4

1 回答 1

1

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

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

无法将类型 id 'file-size-rolled' 解析为 [simple type, class io.dropwizard.logging.AppenderFactory] ​​的子类型:已知类型 ids = [AppenderFactory, console, file, syslog]”

Github 上的拉取请求,以防你感兴趣。

编辑- 还增加了一个事实,即SizeBasedRollingFileAppenderFactory不再需要自定义类,将dropwizard应用程序中1.0.0.

于 2016-09-11T05:59:53.747 回答