Ask Your Question
0

How can I use the appender path specified in the log4rs YAML configuration file to generate a log file name with the current date?

asked 2022-07-31 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-10-07 02:00:00 +0000

plato gravatar image

You can use the strftime format in the file name of the appender path, which will generate a file name with the current date and time. Here's an example YAML configuration file:

appenders:
  file:
    kind: file
    path: "logs/app_%Y-%m-%d.log"
    encoder:
      pattern: "{d} [{t}] {l} - {m}{n}"

root:
    level: debug
    appenders:
    - file

In this example, the %Y-%m-%d format in the file name will be replaced with the current date in the format YYYY-MM-DD.
So, when you run the application on October 31, 2021, the log file generated will be app_2021-10-31.log.

You can also include the current time in the file name by adding the %H-%M-%S format to the file name.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-07-31 11:00:00 +0000

Seen: 12 times

Last updated: Oct 07 '21