Skip to main content Skip to complementary content

Spring Boot log rotation

Create logback.xml files to configure how the Spring Boot logs are generated.

For information about the Spring Boot logging system, see https://www.baeldung.com/spring-boot-logging

Procedure

  1. In $IAM_HOME/apache-tomcat/conf/iam.properties, add a new line to indicate the path to the configuration files of the Spring Boot logs.

    Example

    logging.config=classpath:logback.xml
  2. Create a logback.xml file for each of the related Talend applications:

    Example

    vim $IAM_HOME/apache-tomcat/webapps/(idp|oidc|scim|sts|sts-tac)/WEB-INF/classes/logback.xml
    Information noteNote: Note that the logback.xml files for scim.log and sts-tac.log already exist.
    The content of each logback.xml file should look like:
    <configuration>
             <property name="LOG_PATTERN"
                       value="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(-%5p) [%t] %-40.40logger{39} : %m%n" 
             />
             <appender name="FILE"
                       class="ch.qos.logback.core.rolling.RollingFileAppender">
                   <file>${CATALINA_BASE:-.}/logs/<app>.log</file>
                   <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                      <fileNamePattern>${CATALINA_BASE:-.}/logs/<app>.%d{yyyy-MM-dd}.log</fileNamePattern>
                      <maxHistory>10</maxHistory>
                      <totalSizeCap>100 mb</totalSizeCap>
                   </rollingPolicy>
                   <encoder>
                      <pattern>${LOG_PATTERN}</pattern>
                   </encoder>
             </appender>
             <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
                   <encoder>
                      <pattern>${LOG_PATTERN}</pattern>
                   </encoder>
             </appender>
             <root level="INFO">
                   <appender-ref ref="FILE" />
                   <appender-ref ref="STDOUT" />
             </root>
    </configuration>
    For sts.log and sts-tac.log, you can add the audit related appender to their logback.xml files. Then the content should look like:
    <configuration>
             <property name="LOG_PATTERN"
                       value="%d{yyyy-MM-dd HH:mm:ss.SSS} -%highlight(%5p) [%t] %-40.40logger{39} : %m%n" />
    <!-- %d [%t] %-5p %c %x - %m%n -->
             <appender name="FILE"
                       class="ch.qos.logback.core.rolling.RollingFileAppender">
                   <file>${CATALINA_BASE:-.}/logs/<app>.log</file>
                   <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                      <fileNamePattern>${CATALINA_BASE:-.}/logs/<app>.%d{yyyy-MM-dd}.log</fileNamePattern>
                      <maxHistory>10</maxHistory>
                      <totalSizeCap>100 mb</totalSizeCap>
                   </rollingPolicy>
                   <encoder>
                      <pattern>${LOG_PATTERN}</pattern>
                   </encoder>
             </appender>
             <appender name="AUDIT"
                       class="ch.qos.logback.core.rolling.RollingFileAppender">
                   <file>${CATALINA_BASE:-.}/logs/<app>/audit-tac.log</file>
                   <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                       <fileNamePattern>${CATALINA_BASE:-.}/logs/<app>/audit-tac.%d{yyyy-MMdd}.log</fileNamePattern>
                       <maxHistory>10</maxHistory>
                       <totalSizeCap>20 mb</totalSizeCap>
                   </rollingPolicy>
                   <encoder>
                       <pattern>${LOG_PATTERN}</pattern>
                   </encoder>
             </appender>
             <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
                   <encoder>
                       <pattern>${LOG_PATTERN}</pattern>
                   </encoder>
             </appender>
             <logger name="org.talend.identity.sts.event.map.MapEventLogger" level="DEBUG" additivity="false">
                   <appender-ref ref="AUDIT" />
             </logger>
             <root level="INFO">
                   <appender-ref ref="FILE" />
                   <appender-ref ref="STDOUT" />
             </root>
    </configuration>
    In the example, the log level is defined in each logback.xml file, but you can change the log level globally by adding the following line to the iam.properties file:
    logging.level.root=DEBUG
    The value of the parameter could be
    • TRACE
    • DEBUG
    • INFO
    • WARN
    • ERROR

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!