How to change SpringMVC logging level?

前端 未结 3 500
不知归路
不知归路 2021-01-26 09:43

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.

3条回答
  •  醉梦人生
    2021-01-26 10:04

    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

提交回复
热议问题