Java 在 Spring 中启用日志记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6468999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:12:33  来源:igfitidea点击:

Enabling logging in Spring

javaspringlog4j

提问by KUCH

We are using RAD 7.5 as IDE and also log4j for logging purpose. we want to enable spring logging.

我们使用 RAD 7.5 作为 IDE,同时使用 log4j 进行日志记录。我们要启用 spring 日志记录。

I tried the following

我尝试了以下

  • Added org.springframework.web.util.Log4jConfigListeneras a listener in web.xml. It is added before ContextLoaderListener.
  • log4j.propertiesis present in application war under WEB-INF.
  • Add the following context parameter in web.xml:
  • 增加了org.springframework.web.util.Log4jConfigListener在一个听众web.xml。它是在 之前添加的ContextLoaderListener
  • log4j.properties存在于应用War下WEB-INF
  • 在 中添加以下上下文参数web.xml


<context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>


In log 4j added the following

在日志 4j 中添加了以下内容

log4j.logger.org.springframework=ALL

Even then I am not able to see any output in console or in log file.

即使那样,我也无法在控制台或日志文件中看到任何输出。

Can anyone please let me know the exact steps for enabling spring logging.

任何人都可以让我知道启用 spring 日志记录的确切步骤。

回答by Paul

In your properties file you should have

在你的属性文件中,你应该有

log4j.category.org.springframework=ALL

not

不是

log4j.logger.org.springframework=ALL

See this sectionin the Spring reference.

请参阅Spring 参考中的这一部分

回答by Nick

If you're using log4j2 using the common XML configuration format, add a Logger in your Loggers node:

如果您使用的是使用通用 XML 配置格式的 log4j2,请在您的 Loggers 节点中添加一个 Logger:

<Logger name="org.springframework" level="trace"/>

Normally, the appenders used will be the ones attached to the Root entry.

通常,使用的附加程序将是附加到根条目的附加程序。