How to change SpringMVC logging level?

前端 未结 3 501
不知归路
不知归路 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

    0 讨论(0)
  • 2021-01-26 10:11

    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>
    
    0 讨论(0)
  • 2021-01-26 10:15

    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>
    
    0 讨论(0)
提交回复
热议问题