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:
- The setup/arrangement/configuration.
- real estate
<property name="datePattern" value="yyyy-MM-dd" />
- logger output destination
- Recording device for files
- %d
- 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.
- Can you please rephrase the following sentence in English natively?
- 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.