Currently I have logback configuration file i.e logback.xml
which is src/main/resources
. I want to set the logging level but i want control outside of war.
One solution which i could think of is to externalize it in properties file, load it on server startup and substitute the placeholder. Is there any better way of doing it ? Can't we keep logback.xml
outside of war file ?
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/logFile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 7 days' worth of history -->
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE"/>
</root>
</configuration>
This method is deprecated and exists solely for backward compatibility reasons. Logback components should use getMarkerList() and cater for all available markers and not only the first marker. This fixes LOGBACK-1569 reported by Pelle Krøgholt .
"Root" level does not restrict levels of other loggers, it merely sets the default. So <root level="INFO"> and <logger name="some.name" level="DEBUG"> are perfectly suitable together, and you don't need to relax the "root" level. So both examples should log on debug level for logger named com.
1.2 Logback AdditivityAppenders are added to the loggers. One logger may include more than one appenders. Thus, its log messages are written more than one desired destination systems. Additivity is exactly about this point. The output of a log statement of logger A will go to all the appenders in A and its ancestors.
If you just want to change the log level you don't need to override the whole file, you can do this:
<root level="${log.level:-INFO}">
Then if you set the system property:
-Dlog.level=DEBUG
It will override the default of 'INFO'.
I suggest you use 2 logback configuration files. The first one in the classpath defined as:
<configuration scan="true">
<property file="/otherfolder/project.properties" />
<include file="/otherfolder/logback.xml"/>
</configuration>
and you put all the configuration in the other one. Logback will scan both files for updates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With