在Spring中启用日志记录

KUC*_*UCH 13 java spring log4j

我们使用RAD 7.5作为IDE,也使用log4j进行日志记录.我们想要启用spring logging.

我尝试了以下内容

  • org.springframework.web.util.Log4jConfigListener作为听众添加web.xml.之前添加了它ContextLoaderListener.
  • log4j.properties在申请战中出现WEB-INF.
  • 添加以下上下文参数web.xml:

<context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

在log 4j中添加了以下内容

log4j.logger.org.springframework=ALL
Run Code Online (Sandbox Code Playgroud)

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

任何人都可以让我知道启用弹簧记录的确切步骤.

Pau*_*aul 16

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

log4j.category.org.springframework=ALL
Run Code Online (Sandbox Code Playgroud)

log4j.logger.org.springframework=ALL
Run Code Online (Sandbox Code Playgroud)

请参阅Spring参考中的此部分.

  • 我有log4j依赖1.2.17,它适用于`log4j.logger.org.springframework = ALL`和`log4j.category.org.springframework = ALL`.https://goo.gl/yLwW2b(Logger层次结构)声明Category被Logger取代:`但是,自log4j 1.2版以来,Logger类已经取代了Category类. (2认同)

Nic*_*ick 5

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

<Logger name="org.springframework" level="trace"/>
Run Code Online (Sandbox Code Playgroud)

通常,使用的appender将是附加到Root条目的appender.