How To Set Up Logs with Rolling File Appender

This guide will help you to set up a rolling file appender with Logback-Spring.xml.

Step-by-Step Guide

  1. Create a file in /NAME_OF_API_PROJECT/src/main/resources . The name of the file should be logback-spring.xml
  2. Edit logback-spring.xml with the following code:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true">
    	<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
    		<encoder>
    			<charset>UTF-8</charset>
    			<Pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</Pattern>
    		</encoder>
    	</appender>
    	<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    		<file>C:\tmp\srv\logs\application.log</file>
    		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    			<!-- daily rollover. Make sure the path matches the one in the file element or else
                 the rollover logs are placed in the working directory. -->
    			<fileNamePattern>C:\tmp\srv\logs\application_%d{yyyy-MM-dd}.%i.log</fileNamePattern>
    			<!-- size of the log file-->
    			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
    				<maxFileSize>5MB</maxFileSize>
    			</timeBasedFileNamingAndTriggeringPolicy>
    			<!-- keep 30 days' worth of history -->
    			<maxHistory>30</maxHistory>
    		</rollingPolicy>
    		<encoder>
    			<charset>UTF-8</charset>
    			<pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    		</encoder>
    	</appender>
    	<root level="INFO">
    		<appender-ref ref="consoleAppender" />
    		<appender-ref ref="FILE"/>
    	</root>
    	<logger name="org.openlegacy.impl.rpc.support.DefaultRpcSession" level="DEBUG"/>
    </configuration>

Additional option to enable Tomcat logs

  •        Add the following properties to application.yml
           

    server: 
      tomcat: 
        accesslog: 
          enabled: true 
          directory: C:\tmp\tomcat\


Filter by label

There are no items with the selected labels at this time.