Victor Grazi
Victor Grazi

Reputation: 16520

How can I specify a logback rolling appender in application.yml?

Is it possible to set a rolling appender in application.yml?

In our project, we are able to externalize our application.yml, but other files are more difficult to externalize.

Therefore we would like to include all of our logging properties in application.yml, rather than in logback.xml.

However I am not seeing a way to specify the rolling policy. Can this be done?

Upvotes: 0

Views: 6466

Answers (2)

Andrew
Andrew

Reputation: 876


logging:
file:
  name: log/my-log.log
pattern:
  file: '%d{yyyy-MM-dd HH:mm:ss.SSS, Australia/Sydney} %-5level  - %msg%n'
logback:
  rollingpolicy:
    file-name-pattern: 'log/archived/my-log.%d{yyyy-MM-dd, Australia/Sydney}.%i.log'
    max-file-size: 10MB
    max-history: 60

Upvotes: 1

devshawn
devshawn

Reputation: 711

In the latest release of Spring Boot, assuming you're using Spring Boot 2, log files are automatically rolled at 10MB.

First, specify logging.file or logging.path in your application.yaml to the location of your log file or log path. If you want to change the roll size to something other than 10MB, change the property logging.file.max-size.

By default, previously rotated files are kept indefinitely unless logging.file.max-history is set. Set this to the number of rolled files you would like to keep. These only work for the default logback provider included with Spring Boot.

You can see all of the logging properties that can be set in application.yaml in reference 1 below:

References:

  1. Spring Boot Common Application Properties
  2. Logging File Output Documentation

Upvotes: 1

Related Questions