So I have a project for which I need to set up logback. This project is strictly spring MVC(can't be upgraded to spring-boot). It is deployed on wildfly 17.0.1.
I have a few questions regarding this.
- So I did the setup of logback and logs are generated fine. But auto scan of the configuration file logback.xml is not working.
My setup
This is the only dependency I've added to my project. Logback is set up to bridge via slf4j(set up in wildfly)<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.9</version>
</dependency>
This is my logback.xml file.
<configuration scan="true" scan_period="2 seconds" debug="false" packagingData="false">
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
<property name="LOG_DIR" value="path/to/dir" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/server.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<!-- <level>INFO</level>-->
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/server.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>365</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${PATTERN}</pattern>
</encoder>
</appender>
<appender name="APP_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/app.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<!-- <level>INFO</level>-->
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/uix.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>365</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${PATTERN}</pattern>
</encoder>
</appender>
<appender name="ACCESS_APP_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/access.app.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<!-- <level>INFO</level>-->
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/access.app.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>365</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${PATTERN}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="FILE"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
</root>
<logger name="com.package.path" level="INFO" additivity="false">
<appender-ref ref="ACCESS_APP_FILE"/>
</logger>
<logger name="com.package.path.2" level="INFO" additivity="false">
<appender-ref ref="APP_FILE"/>
</logger>
</configuration>
This logback.xml file is placed in wildfly's standalone folder for me to be able to change the runtime log level(reference to logback.xml is given in standalone.sh). But this is not working and after searching for it, people suggested putting it in the target folder which does not make sense(since I then can't change the log level once *.war is deployed).
So can someone suggest what can be done here where I can achieve changing log level at runtime?
- The console Appender does not work at all. Logs that are supposed to be seen in the console, are stored in a log file. But I also want them to be displayed on the console too. I'm using the same configuration file as above. Can you help me with this too?
Things I've done
- Added jboss-deployment-structure.xml and excluded other logging libraries from wildfly or even my own project.
- Setting LogContext and setting configuration file in the project which also didn't work.
Any help is much appreciated :)