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
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:
I'm using Spring Boot and the exclusion I'm making is logback-classic as shown in the following snippet:
You can specify the required package name as can be seen in the following example:
Now you can see only WARN, ERROR and FATAL logs in console.
Before you do, you should have get some knowledge of :
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
fromspring-core
Add SLF4J and log4j
configure log4j.properties(You can also use xml file)
Now, the annoying spring debug log is going away.Enjoy coding!
The answer is from spring.io doc,for origin click here
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.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.
or whatever log level level you like.