2

First, I referenced this thread and this documentation, and various articles like this one, but I'm obviously missing something.

I have tried various combinations. What I currently have is

logging:
  level.root: trace
  file:
    name: ${PWD}/logs/spring.log
    max-size       : 1MB
    max-history    : 3
    total-size-cap : 2MB
  pattern:
    file              : "%d{yyyy-MM-dd HH:mm:ss} %-5level [%thread] [%class{36}] - %msg%n"
    console           : ${logging.pattern.file}
    rolling-file-name : ${PWD}/logs/archive.%i.log

also tried

logging.logback.rollingpolicy:
    file-name-pattern : ${PWD}/logs/${spring.application.name}.%i.log
    max-file-size     : 2MB

With root log level set to TRACE the logs go over 2MB almost immediately.

It works fine when we use a separate XML file to configure logback, but we're trying to remove the need.

Anish B.
  • 9,111
  • 3
  • 21
  • 41
Paul Hodges
  • 13,382
  • 1
  • 17
  • 36
  • when i use rolling with YAML, *FileNamePattern* needs to contain a valid DateToken. like followe worked. 'logging.logback.rollingpolicy.file-name-pattern: ${PWD}/logs/${spring.application.name}.%d{yyyy-MM-dd}.%i.log' – BlackC Sep 09 '22 at 08:55
  • Tried that too, though I don't see any yaml triggers for rolling by date. Didn't change anything. :( – Paul Hodges Sep 09 '22 at 13:41
  • @PaulHodges I got it working. I did something. I will update with the new answer. Give me sometime. – Anish B. Sep 09 '22 at 15:25

1 Answers1

2

This is the best yaml logback configuration that's working for me with lot of difficulties:

logging:
  file:
    path: /Volumes/Local Disk/logs
    name: spring.log
  logback:
    rollingpolicy:
       total-size-cap: 1MB
       max-history: 3
       max-file-size: 1MB
       file-name-pattern: /Volumes/Local Disk/logs/spring.%d{yyyy-MM-dd}.%d{HH:mm:ss.SSS}.%i.log.gz
  level:
     root: trace

Screenshot:

enter image description here

Anish B.
  • 9,111
  • 3
  • 21
  • 41
  • @PaulHodges Is this configuration working for you ? – Anish B. Sep 11 '22 at 04:05
  • @PaulHodges Please accept this if this has helped you in anyway. I think this should work but the only doubt I have is about its stability via properties. Otherwise, it will work as expected. – Anish B. Sep 12 '22 at 10:52
  • 1
    Will check it today and confirm. – Paul Hodges Sep 12 '22 at 13:57
  • @PaulHodges Have you checked ? The bounty is getting over. – Anish B. Sep 13 '22 at 11:02
  • 1
    I finally got it to roll, but can't set the file name, or the size. I can tell it where to build subdirectories, but can't set the names of those either. Thanks for the help, upvoted the effort, but still nowhere close to solved. :( – Paul Hodges Sep 13 '22 at 13:18
  • @PaulHodges At least, it's rolling. :) I guess the question was about why rolling was not happening. – Anish B. Sep 13 '22 at 13:29
  • Not really. It's rolling as the new default behavior at 10MB. I really want to be able to control size, number, name, and location of the archives as well as the original log. What actually *triggers* the log aside from the defaults? – Paul Hodges Sep 13 '22 at 15:34