user3198603 user3198603 - 16 days ago 7
Java Question

Change Log level at runtime without server restart?

I am using the logback as implementation with SL4j interface. Here is the configuration

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/prod.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>logs/prod.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>700MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>


<logger name="com.ecom" additivity="false" level="ERROR">
<appender-ref ref="FILE" />
</logger>


I want to change the level to Info or debug at runtime through configuration or external property change in production without restarting the server. Is it possible ?

FYI ,I am using Weblogic as application server and also Spring frameworks for other purposes >

Answer

Variable substitution is your friend here. Default values for variables should be helpful as well.

See also variable scoping.