简体   繁体   English

Log4j 没有捕获异常

[英]Log4j is not catching exceptions

I am using google app engine and I am having trouble with log4j.我正在使用谷歌应用引擎,但在使用 log4j 时遇到了问题。 Basically I am testing my app and the exceptions are being detected by the dashboard, but not log4j.基本上我正在测试我的应用程序并且仪表板检测到异常,但不是 log4j。 I am using the following:我正在使用以下内容:

 catch (Exception e) {
       logger.warn("Exception Alert", e);
       e.printStackTrace();
   }

Is this the correct way to catch exceptions using Log4j?这是使用 Log4j 捕获异常的正确方法吗? It works for some exceptions now.它现在适用于一些例外情况。 But not all.但不是所有的。 I want to catch a NumberFormatException (empty string) but this is isn't working.我想捕获一个 NumberFormatException(空字符串),但这不起作用。

Yes, it's correct but the logger should be initialized via LogFactory.getLog() and log level should be at least WARN .是的,它是正确的,但logger应该通过LogFactory.getLog()初始化并且日志级别应该至少是WARN Also log4j should be on classpath and configured like in this examples . log4j 也应该在类路径上,并像本示例中一样进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM