Warm tip: This article is reproduced from stackoverflow.com, please click
logging spring-boot yaml logback spring-logback

How to put the current date in logback filename with yaml?

发布于 2020-03-27 15:46:48

In springboot, I'm trying to put the current date in my log filename lke this : 2020-01-31-log.log

I tried this :

logging:
  level:
    root: info
    com.inyt.inytcirculationportal: debug
  file:
    name: "logs/%d-log.log"

but nothing seems to work.

Questioner
Maksson
Viewed
92
Clive Bixby 2020-01-31 18:26

Putting the date in the log file like this does not seem like a good idea to me, even if you were able to inject it somehow in your properties.
What if your application runs several days or months? You would only get a file per day if you restart the application at midnight. If you haven't done so, I'd recommend looking at the Logback RollingFileAppender, which will automatically archive your current log file and start a new one at the interval you configured. With the date pattern you mentioned, your log folder could look like this:

  • app.log <- currently active log
  • app.2020-01-30.log <- yesterday's log
  • app.2020-01-29.log <- you get the idea ;-)