0

I use the following logging config in my Spring Boot apps and save logs in that log file. But it creates many files (e.g. application.log.2023-02-26.0.gz) and after a certain period of time, I need to delete old log files based on size or creation date.

logging:
  pattern:
    console: "%d %-5level %logger : %msg%n"
    file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
  level:
    org.springframework.web: error
    org.hibernate: error
    com.demo.app: debug
  file:
    name: './logs/application.log'

So, how can I remove old log files automatically?

Jack
  • 1
  • 21
  • 118
  • 236
  • 1
    Note: read the lower answers to the duplicate question. `file.max-history: 50` will be part of your solution. 50 is an arbitrary number – DwB Mar 01 '23 at 16:50
  • @CLOSERS Why did you close without reading the question? I had already read that page but not solved my problem. I hope you read at least comments. – Jack Mar 01 '23 at 20:04
  • @DwB It is for rolling, but I want to remove old log files completely. – Jack Mar 01 '23 at 20:05
  • As noted in my comment, file.max-history defines the maximum number of files that will stick around. – DwB Mar 02 '23 at 14:03
  • @DwB `logging.file.max-size` seems to work, but `logging.file.max-history` is not and it continues to create a new log even if it exceed the given max number. Any idea? – Jack Mar 02 '23 at 14:14

0 Answers0