ERROR in ch.qos.logback.core.joran.spi.Interpreter- no applicable action for [maxHistory] - spring-boot

When i am using spring boot in my application i am getting below error while starting the spring boot application main method. Please note that application is running in kotlin and we are triggering spring boot start up from a seperate class. when i run the application from workspace it run successfully and start up but launching the application from a packaged jar throws this error.
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter#20:21 - no applicable action for [maxHistory], current ElementPath is [[configuration][appender][maxHistory]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter#37:21 - no applicable action for [maxHistory], current ElementPath is [[configuration][appender][maxHistory]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter#54:21 - no applicable action for [maxHistory], current ElementPath is [[configuration][appender][maxHistory]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:222)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:73)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:306)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:281)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
without using spring boot it is working absolutely fine. I saw this post
Logback file error: no applicable action for [configuration], current ElementPath is [[configuration][configuration]] but it didn't help.
my logback.xml:
The tag in the logback is creating the issue how to resolve it ?
<appender name="HealthRollingFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${app.logpath:-log}/${log.base.name}-health.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${app.logpath:-log}/${log.base.name}-health-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- Number of days of log files to keep -->
<maxHistory>14</maxHistory>
</appender>
My pom has multipl dependencies but below are some springboot dependencies which this code uses:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.3.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
``` <groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>```
<version>5.3.8</version>
</dependency>
I checked multiple posts on this forum but there doesn't seems to be a solution fitting in this case. without springboot the application running fine.

Edit your logback file as follows:
<appender name="HealthRollingFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${app.logpath:-log}/${log.base.name}-health.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${app.logpath:-log}/${log.base.name}-health-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!-- Number of days of log files to keep -->
<maxHistory>14</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>

Related

Spring Boot SLF4j Logback

I have a small SpringBoot MvC app. with those dependencies:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot-starter-test.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
I put a logback-test.xml file in the /src/test/resources/ and when I run the test it works fine
<configuration debug="true" scan="true" scanPeriod="150 seconds">
<property name="LOG_DIR" value="logs-test" />
<appender name="FILE_INFO"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/app_info.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} -
%msg%n
</Pattern>
....
</configuration>
but when I add to the file /src/test/resources/application.properties:
# logging level
logging.level.root=error
logging.level.org.springframework=ERROR
logging.level.com.plats.bruts=ERROR
but it seems not to work, because I see the DEBUG level on the console when running the test:
10:16:08.039 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class eu.europa.ec.oib.kw.frontoffice.repository.autorisation.AutorisationPersonneRepositoryTest]
10:16:08.047 [main] DEBUG org.springframework.test.context.BootstrapUtils
Make sure to use #SpringBootTest annotation when testing spring boot apps for spring boot to load default logback logging.
For the most part you can configure without needing custom logback xml file and can be managed using application.properties.
For non spring boot test cases you've to provide your own logback xml file.
For custom configuration you should build your file based on base.xml default provided in the spring boot library ( has both file and console appender defined) so you can import the defaults and add specific configuration based on your need.
This way you still manage the default configuration attributes from application properties for spring boot tests. Also rename the file to end with spring extension so spring boot can take control of logging initialization.
Something like
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
!-- custom configuration goes here --!
</configuration>

No appenders could be found for logger in local server but same application works fine in Production server- log4j

We have two servers. One for QA and another is Production server (hosted on AWS). I have used "apache-tomcat-8.5.16" server in both environment. We have developed Spring boot app and Log4j configuration is same for applications deployed in both servers.
logging.level.net.companyname= DEBUG
logging.level.com.google.api.ads.dfp.lib.client.DfpServiceClient.soapXmlLogger=WARN
logging.level.com.google.api.ads.dfp.lib.client.DfpServiceClient.requestInfoLogger=INFO
Yet, in local server (used for QA), we are getting the error "log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment" .
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
But in Production server we are getting logs without any problem.
If it does matter, below is the pom.xml configuration related to log4j.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
Even configurations inside "apache-tomcat-8.5.16/conf/logging.properties" file are also same in both servers.
How to get logs as we are getting in Production environment?
What else would make difference when both tomcat server versions are same and same war is deployed on both of them with same configuration settings?
Thank you.
Update:
I downloaded the war file to local from server for testing and even there, log4j is working fine. What else do I need to check?
Thank you.
This is an alternative and recommended solution.
After waiting for a week, I thought, why should I worry on framework that has reached it's end of life. I upgraded to log4j2 and provided log4j2.xml file in the classpath (in my case, /src/main/resources, working in STS-Spring Tool Suite, Spring application.).
However the actual reason for this weird behavior is still unknown.
Below is the pom.xml file tailored only log4j2 dependency for verbosity.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - ***CustomLog*** %msg ***/CustomLog***%n" />
</Console>
<File name="traceLoggerFile" fileName="logs/trace.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
<File name="debugLoggerFile" fileName="logs/debug.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
<File name="infoLoggerFile" fileName="logs/info.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
<File name="errorLoggerFile" fileName="logs/errors.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Logger name="com.packageName" level="TRACE">
<AppenderRef ref="traceLoggerFile" level="TRACE" />
<AppenderRef ref="debugLoggerFile" level="DEBUG" />
<AppenderRef ref="infoLoggerFile" level="INFO" />
<AppenderRef ref="errorLoggerFile" level="ERROR" />
</Logger>
<Root level="DEBUG">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
You need to give proper package name or class name in this line
<Logger name="com.packageName" level="TRACE">
Will be happy if anyone can find the actual reason.
Thank you.

Tomcat logs are being written to syslog instead to the application log in Spring Boot and Log4j

It's a Spring Boot application with Log4j for logging.
All logs from org.apache.catalina.* are being sent to syslog, and it includes also uncaught exceptions.
Our app uses Log4j (v1) since it uses legacy code dependencies that use Log4j.
Spring Boot version is 1.5.2.RELEASE.
I believe that with correct set-up, also tomcat logs will be written to the same file that is configured in the log4j.xml, but i couldn't find any answer to that problem.
pom.xml (relevant parts):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring Logging -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%t] %5p %c{1} - %m%n" />
</layout>
</appender>
<!-- File appender -->
<appender name="logFileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="/tmp/myappname.log"/>
<param name="Append" value="true" />
<param name="BufferedIO" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%t] %5p %c{1} - %m%n" />
</layout>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="consoleAppender" />
<appender-ref ref="logFileAppender" />
</root>
</log4j:configuration>
Could you try excluding it in the actuator artifact?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Based on your comment:
If I understood correctly, the application is logging fine, it's the servlet container the logging to syslog when exceptions bubble up, isn't?
Could you also try adding:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-log4j</artifactId>
</dependency>
and / or passing where log4j config file is located:
-Dlog4j.configuration=<path to file>
If these don't work, the only thing I could think of is that you are using Spring Boot 1.5.x doesn't get along with Log4j and likely requires to uplift it to Log4j2

Deploying spring-boot application to WildFly 8 causes container logs to be redirected

I'm trying to deploy a spring-boot application using logback to an existing WildFly 8 container, but as soon as the application has deployed all the container logs stop being written to server.log and end up being captured by the application logs.
The symptoms are similar to those described in WildFly not logging after deploying app with Logback. If I deploy an application which manually contains logback/slf4j dependencies, the application behaves as I'd expect (application logs go to application logfile, container logs go to server.log), so I'm assuming it's something to do with spring-boot? Can I configure this such that the container logging continues to be handled by Wildfly?
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.logging</groupId>
<artifactId>logger-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="path_base" value="d:/test-logger/" />
<property name="pattern"
value="%date{ISO8601} %level %class{30} %thread %msg %mdc %ex{full} %n" />
<!-- Simple File Appender -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${path_base}test-logger.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${path_base}/archive/%d{yyyy-MM,aux}/test-logger.log.%d.%i.gz
</fileNamePattern>
<maxHistory>90</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date{ISO8601} %level %class{30} %thread %msg %mdc %ex{full} %n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="file" />
</root>
</configuration>
jboss-deployment.xml
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
Spring boot initializer
package com.test;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
#SpringBootApplication
public class BootApp extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
return builder.sources(BootApp.class);
}
}
I had similar problem when I deployed spring-boot application to websphere. After application prints banner all the log messages from websphere are logged into application log.
The problem occurred because spring-boot adds as one of its dependencies jul-to-slf4j.jar . This jar implements classes java.util.logging.* and websphere is also using java.util.logging hence by excluding jul-to-slf4j.jar from spring boot I was able to direct all websphere messages to container log and the application logs were written to application log.
I had a similar problem:
Running Spring-boot 1.5.8 on Wildfly 9.0.2Final
I had to exclude the following before the logging was handled by the container:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
spring-boot-starter-data-jpa has spring-boot-starter-logging which had the dependencies i excluded.

Disabling Spring log, to have readable logs

How can I disable Spring logs to have log outputs that I can easily read or someone else can read.
An answer to a similar question at, how to disable spring bean loading log suggested to comment out all lines having org.springframework substring in log4j.properties file. In my case there no such lines.
Here is log4j.properties
# Define the root logger with appender file
log4j.rootLogger = DEBUG, stdout
# Define the file appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# Set the name of the logs destination
log4j.appender.stdout.target=System.out
# Set the immediate flush to true (default)
log4j.appender.stdout.ImmediateFlush=true
# Set the threshold to debug mode
log4j.appender.stdout.Threshold=debug
# Set the append to false, overwrite
log4j.appender.stdout.Append=false
# Define the layout for appender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.conversionPattern=%d{yyyy-MM-dd}:%m%n
Your default logging, for everything that isn't explictily specified, is DEBUG. So everything is logged at that level (judging from your configuration), basically you are flooding your logs. You should not remove loggers for org.springframework you should add them and set another level for them.
log4j.logger.org.springframework=INFO
or whatever log level level you like.
Before you do, you should have get some knowledge of :
1.How to add maven dependency
2.Where to put log4j configuration file
OK, return to the question.The top answer is not working for spring 4.x, if you are using spring4.x try following 3 steps:
remove common-logging from spring-core
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Without this step, no matter what you put in log4j configuration file is not working, cause spring is using common-logging my boy!
PS:Within lots of spring modules, spring-core is the the only module that explicitly depends on commons-logging.
Add SLF4J and log4j
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
configure log4j.properties(You can also use xml file)
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t
%c{2}:%L - %m%n
log4j.category.org.springframework.beans.factory=INFO
Now, the annoying spring debug log is going away.Enjoy coding!
The answer is from spring.io doc,for origin click here
All the answers gave examples with configuration in log4j.properties, which is what was asked. I had the same problem but I was using configuration in log4j2.xml and answers here lead me to a solution.
In case someone is on the same boat as me, here is what I did: I added a node Logger with name org.springframework and level WARN as shown in the following sample:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.springframework" level="WARN"/>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
I'm using Spring Boot and the exclusion I'm making is logback-classic as shown in the following snippet:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
You can specify the required package name as can be seen in the following example:
log4j.logger.com.foo=WARN
Now you can see only WARN, ERROR and FATAL logs in console.
I was also facing this same issue. Springframework logging was not getting removed even after log4j configuration. Then I found that its logging depends on commons-logging.
You have to disable commons-logging from the dependency in pom.xml file of the web app.
Even after removing commons-logging from pom.xml please check the dependency hierarchy available in Eclipse or STS IDE. This will help in knowing if somehow its getting added because of some other dependency management which we may not be knowing.
After removing dependency just add log4j.logger.org.springframework=ERROR to your log4j configuration. This will help.

Resources