我在从 Spring 服务记录 RuntimeExceptions 时遇到问题。
我的配置是:
罐子(Maven):
- 我已经排除了公共日志记录
- 我在类路径上有 log4j 和 sl4j
网页.xml:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
log4j.properties:
log4j.rootLogger=INFO, infrastructure
log4j.appender.infrastructure=org.apache.log4j.FileAppender
log4j.appender.infrastructure.File=/opt/logs/infrastructure.log
log4j.appender.infrastructure.layout=org.apache.log4j.PatternLayout
log4j.appender.infrastructure.layout.ConversionPattern=%d{HH:mm:ss} (%t) %-5p [%c] - %m%n
在服务方法中:
throw new IllegalStateException();
我应该提到我正在使用 Spring MVC。Spring 版本是 3.0.5。Tomcat 7.0.11 作为 Web 服务器。
我的目标是让 IllegalStateException 像任何其他正常异常一样被记录到我的日志附加程序中。我寻找一种方法来注册全局 UncaughtExceptionHandler 但找不到任何方法,所以我猜我的运行时异常没有被记录。相反,它们被输出到标准输出。
我应该如何解决这个问题?任何帮助表示赞赏。
欧根。