Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure rolling file appender within Spring Boot's application.yml

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

like image 828
ele Avatar asked Apr 28 '15 11:04

ele


People also ask

What is rolling file Appender in Log4j2?

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.

How do I put Logback xml in spring boot?

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.

What is a rolling file?

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.

How do I create a log file in spring boot project?

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.


1 Answers

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> 
like image 114
Donovan Muller Avatar answered Oct 12 '22 23:10

Donovan Muller