如何更改SpringMVC日志记录级别? [英] How to change SpringMVC logging level?

查看:246
本文介绍了如何更改SpringMVC日志记录级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IntelliJ创建了一个新项目(SpringMVC),但我不知道如何更改SpringMVC的日志记录级别,因此我只能看到警告/错误.

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.

这就是它的外观-当我运行测试时,控制台上充斥着INFO和测试结果.拜托,帮我摆脱这个.

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.

致谢.

推荐答案

XmlBeanDefinitionReader 不是spring MVC的一部分,它位于spring-beans模块中. 因此,我想您的问题本质上是如何管理Spring Log.

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.

从日志记录配置的角度来看,spring文件的行为与其他任何文件一样.

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

spring内部使用commons-logging:在此文件中,查看方法 loadBeanDefinitions (我使用的是spring 3.2.0),它负责打印您在此代码段中显示的第一条语句.

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.

它在内部使用在其超类 AbstractBeanDefinitionReader 中定义的记录器 这是一个公共记录类.这意味着您可以使用任何实际的实现并根据需要配置日志记录. 例如,您可以使用log4j或java.util.logging,因为公用记录实际上并未为记录工具提供具体的实现.

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.

现在您可能已经在使用某些日志记录实现.如果是log4j,则只需配置公共日志以在后台使用log4j实现,然后像在log4j中通常那样配置loggers/appender.

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

这应该可以,但是要将commons-logging与log4j相关联,如果我没记错的话,您可能想使用 commons-logging.properties 文件并将log4j与 org相关联. apache.commons.logging.Log = org.apache.commons.logging.impl.Log4jLogger

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

希望这会有所帮助

这篇关于如何更改SpringMVC日志记录级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆