Search code examples
spring-bootlogbackslf4j

Springboot Logging Pattern For Rolling Logs


I am using Springboot version 2.7 and trying to configure the log pattern to be daily rolling.

I am currently using just the application properties file to configure the logging as that's the preference.

I added the following line in the properties file but does not seem to work

logging.logback.rollingpolicy.file-name-pattern=myservice-%d{yyyy-MM-dd}.log

Any clues what I may be missing?

Also, is there a way to check daily log rolling without having to wait for EOD :)


Solution

  • First, you have to specify the file name:

    logging.file.name=myservice.log
    

    then you can use the rolling file name pattern

    logging.logback.rollingpolicy.file-name-pattern=myservice-%d{yyyy-MM-dd}.log
    

    To force the file change you could set the size to something small

    logging.logback.rollingpolicy.max-file-size=100K
    

    To specify the directory you must set this property

    logging.file.path=/var/logs
    

    The documentation can be found here: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.logging