How to create folders by date in logback?

In logback, you can use %d to generate folders based on the date. The specific steps are as follows:

  1. The setup/arrangement/configuration.
  2. real estate
<property name="datePattern" value="yyyy-MM-dd" />
  1. logger output destination
  2. Recording device for files
  3. %d
  4. pattern for dates
<appender name="File" class="ch.qos.logback.core.FileAppender">
  <file>/path/to/logs/%d{yyyy/MM/dd}/log.txt</file>
  <encoder>
    <!-- encoder配置 -->
  </encoder>
</appender>

In the example above, %d{yyyy/MM/dd} will generate a folder path based on the current date, such as /path/to/logs/2022/01/01/log.txt.

  1. Can you please rephrase the following sentence in English natively?
  2. DocumentAppender
<root level="info">
  <appender-ref ref="File" />
</root>

In this way, logback will automatically create a new folder at the end of each date and write the log files into it.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds