javayamldropwizardrollingfileappenderfileappender

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


I have been facing a run time error since I moved from dropwizard-core 0.7.1 to 1.0.0 which is as following -

/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

The problem is that even when I've made changes to the config.yml accordingly and compiled the project successfully. Still while trying to run the project I am getting the same error.

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

In case required the file-size-rolled is defined as follows -

@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;

What changes related to the version upgrade am I missing here?


Solution

  • Since dropwizard v0.9.0 all file rotation policies have been done using the class FileAppenderFactory. So, try replacing file-size-rolled with file and it should work.

    Also, ensure you don't have any of the 0.7.1 jars sticking around in the class-path. I'm guessing they're around since you didn't get the following error message.

    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]"

    The Pull Request on Github in-case you're interested.

    Edit - Also adding to the fact that the customised class SizeBasedRollingFileAppenderFactory wouldn't be required anymore post the changes in dropwizard application in 1.0.0.