sattu
sattu

Reputation: 650

Log file not generated in dropwizard

I have following log scheme. I want to rotate logs every 4 hours. But when I start application with these settings, ./logs/mylogs.log file is not generated. I have logs directory created in application's directory.

It works fine if I change filename pattern to include minute as well like - archivedLogFilenamePattern: ./logs/mylogs-%d{yyyy-MM-dd-hh-mm}.log.gz I am confused why it does not work for hourly pattern?

logging:
  level: WARN
  appenders:
    - type: console
      threshold: WARN
    - type: file
      threshold: WARN
      logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"
      currentLogFilename: ./logs/mylogs.log
      archive: true
      archivedLogFilenamePattern: ./logs/mylogs-%d{yyyy-MM-dd-hh}.log.gz
      archivedFileCount: 4

Using dropwizard 1.3.7

Upvotes: 1

Views: 602

Answers (1)

Denny Abraham Cheriyan
Denny Abraham Cheriyan

Reputation: 1268

Dropwizard uses Logback for logging. The rolling policy used here is TimeBasedRollingPolicy.

The fileNamePattern to rollover at the beginning of every hour:

  archivedLogFilenamePattern: ./logs/mylogs-%d{yyyy-MM-dd_HH}.log.gz

Not sure if there is a way to rollover every n hours. You might want to consider using FixedWindowRollingPolicy, which dropwizard supports. This will allow you to rollover based on size. Eg -

  - type: file
    threshold: ALL
    maxFileSize: 100MB
    currentLogFilename: ./logs/max-file-size-example.log
    archivedLogFilenamePattern: ./logs/max-file-size-example-%i.log.gz
    archivedFileCount: 5

Upvotes: 1

Related Questions