Is is possible to configure a daily file appender within the application.yml of a Spring Boot application?
i.e. filenamePattern: myfile.%d{yyyy-MM-dd-HH-mm-ss}.log
I have configuration such as the following in my application.yml file.
logging: file: /mypath/myfile.log level: mypackage: INFO
Thanks
Log4j2 RollingFileAppender is an OutputStreamAppender that writes log messages to files, following a configured triggering policy about when a rollover (backup) should occur. It also has a configured rollover strategy about how to rollover the file.
To configure Logback for a Spring Boot project via XML, create the logback. xml or logback-spring. xml file under the src/main/resources folder. The configuration in XML file will override the logging properties in the application.
Log file rolling offers the following benefits: It defines an interval over which log analysis can be performed. It keeps any single log file from becoming too large and assists in keeping the logging system within the specified space limits.
To make Spring Boot write its log to disk, set the path and filename. With this configuration, Spring Boot will write to the console and also to a log file called spring. log , at the path you specify.
The default file appender is size based (10MB).
In your logback.xml
just configure a TimeBasedRollingPolicy
as described here
I.e. something like:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <appender name="ROLLIN" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${LOG_FILE}</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern> </rollingPolicy> </appender> <root level="INFO"> <appender-ref ref="ROLLIN" /> </root> <logger name="org.springframework.web" level="INFO"/> </configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With