How to change SpringMVC logging level?

2019-03-05 08:13发布

I created a new project (SpringMVC) using IntelliJ and I don't know how to change logging level of SpringMVC, so I could only see warnings/errors.

enter image description here That's how it looks - when I run tests, the console is cluttered with INFO and test results. Please, help me get rid of this.

Regards.

3条回答
可以哭但决不认输i
2楼-- · 2019-03-05 08:45

If you´re using logback.xml you can modify the package log level.

     <logger name="here.you.package" level="DEBUG" additivity="false">
    <appender-ref ref="stdout" />
</logger>
查看更多
狗以群分
3楼-- · 2019-03-05 08:58

XmlBeanDefinitionReader that you've mentioned in the screenshot is not a part of spring MVC, it resides in spring-beans module. So I guess your question is essentially how to manage spring logs.

Well, spring files from the point of view of logging configuration behaves just like any other file.

Internally spring uses commons-logging: In this file take a look on method loadBeanDefinitions (I'm using spring 3.2.0) it's responsible to print the first statement you show in this snippet.

It uses internally a logger defined in its superclass AbstractBeanDefinitionReader and it's a commons logging class. This means that you might use any actual implementation and configure the logging as you wish. For example you may use log4j or java.util.logging since commons logging doesn't actually provide a concrete implementation for logging facilities.

Now you're probably already using some logging implementation. If its log4j you just need to configure the commons logging to use the log4j implementation under the hood and then configure loggers/appender as you usually do in log4j.

For example, for property files based configuration, use:

log4j.category.org.springframework=WARN, yourAppenderToHandleSpringLogs

This should work, but to associate commons-logging with log4j, If I'm remember correctly you might want to use commons-logging.properties file and associate the log4j: org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4jLogger

More information on actual configuration can be found :here

Hope this helps

查看更多
爷、活的狠高调
4楼-- · 2019-03-05 09:03

If you are using log4j in your log4j.properties:

log4j.logger.org.springframework=WARN

or log4j.xml:

<logger name="org.springframework">
    <level value="warn" />
</logger>
查看更多
登录 后发表回答