问题描述
如何禁用弹簧日志以具有可以轻松阅读或其他人可以阅读的日志输出. 如何禁用Spring Bean Log 建议评论所有具有org.springframework substring> log4j.properties file的行.就我而言,没有这样的行.
这是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
推荐答案
您的默认记录(对于未指定的所有内容)都是 debug .因此,所有内容都以该级别记录(从您的配置来看),基本上您正在淹没日志.您不应删除org.springframework的记录仪,您应该添加它们并为其设置另一个级别.
log4j.logger.org.springframework=INFO
或您喜欢的任何日志级别.
其他推荐答案
在您这样做之前,您应该有一些了解:
1.How to add maven dependency 2.Where to put log4j configuration file
好吧,返回问题. 如果您使用的是spring4.x,则最高答案是不适用于弹簧4.x ,请尝试以下3个步骤:
-
从spring-core
中删除common-logging<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>
没有此步骤,无论您在log4j配置文件中放置什么都无法正常工作,因为春季使用common-logging我的男孩!
PS:在许多弹簧模块中,spring-core是唯一明确依赖于commons-logging的模块. -
添加slf4j和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>
-
配置log4j.properties(您也可以使用XML文件)
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
现在,烦人的春季调试日志正在消失.
答案来自spring.io doc,origin clock 在这里
其他推荐答案
所有答案给出了log4j.properties中配置的示例,这就是所要求的.我遇到了同样的问题,但是我在log4j2.xml中使用了配置,并在这里回答了我的解决方案.
,如果有人和我在同一条船上,这是我所做的:我添加了一个带有名称org.springframework和Level警告的节点记录器,如以下示例所示:
<?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>
我正在使用Spring Boot,我要做的排除是木制 - 经典,如以下片段所示:
<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>
问题描述
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>