Invalid action for totalSizeCap in logback spring loading logging

I am trying to limit the maximum number of log files using the "totalSizeCap" element from the log. I use the spring boot application, so I include the login in it as follows:

logback.xml

<?xml version="1.0" encoding="UTF-8"?> <configuration debug="true"> <include resource="log4j/logback-${spring.profiles.active}.xml"/> </configuration> 

log4j / Logback-DEV.xml

 included> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <Pattern> %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n </Pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>/tmp//log/log.out</file> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <fileNamePattern>/tmp/log/log_%d{yyyy-MM-dd}.%i.out</fileNamePattern> <maxFileSize>10MB</maxFileSize> <maxHistory>1</maxHistory> <totalSizeCap>2MB</totalSizeCap> </rollingPolicy> <encoder> <charset>UTF-8</charset> <pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n </pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> <logger name="com.company" level="INFO" /> <logger name="org.springframework" level="ERROR" /> </included> 

ERROR

 ERROR in ch.qos.logback.core.joran.spi.Interpreter@17 :27 - no applicable action for [totalSizeCap], current ElementPath is [[configuration][appender][rollingPolicy][totalSizeCap]] 

How to limit log files?

+6
source share
1 answer

I assume logback.xml not suitable for indicating what you want. Instead, you should use the logback-spring.xml . This is because the log structure is loaded before the ApplicationContext (so that the context can log some initial things), then the context loads logback-spring.xml to change the log settings the rest of the time the application is running. Essentially, I assume that ${spring.profiles.active} not replaced by an active profile.

From reference

If possible, we recommend using the -spring options for yours (e.g. logback-spring.xml , not logback.xml ). If you use standard configuration locations, Spring cannot fully control log initialization.

Reading a little more, answering this question, there is a section specifically devoted to Magazine Extensions . It looks like you need to use the <springProperty> element in the configuration to open the property.

 <springProperty scope="context" name="activeProfile" source="spring.profiles.active" defaultValue="DEV"/> <include resource="log4j/logback-${activeProfile}.xml"/> 
0
source

All Articles