使用Log4j捕获异常

时间:2013-04-02 16:09:27

标签: java eclipse google-app-engine exception dashboard

例外的log4j.category.DataNucleus是什么?所以我想尝试将Log4j与Google App Engine一起使用,但是在测试期间,Lo4j没有接收到异常(它们被仪表板拾取)。

此外,我希望获取所有错误。所以我把它添加到主类。这会不会包括所有错误,包括fatel?

   logger.fatal ("App Error");

好的,我试过这个:

 }
     catch(Exception e) {
            logger.warn("Log4j has caught n exception!", e);
            e.printStackTrace();
        }

然而,异常显示在仪表板中,但它不是log4j,因为它没有给我“Log4j已经捕获n异常!”。

1 个答案:

答案 0 :(得分:0)

例外的log4j.category.DataNucleus是什么?

log4j.logger.DataNucleus

常规

我不使用Eclise或Log4J(当然,除了DataNucleus使用它)。我的日志配置文件中包含以下内容。

<强> log4j.properties

log4j.appender.A1 = org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout = org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern = %d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n

[...]

# Tighten logging on the DataNucleus categories to WARN.
# This DataNucleus logging configuration appears redundant; in production,
# DataNucleus uses Java logging instead.
log4j.logger.DataNucleus                 = WARN, A1
log4j.logger.DataNucleus.JDO             = WARN, A1
log4j.logger.DataNucleus.Persistence     = WARN, A1
log4j.logger.DataNucleus.Query           = WARN, A1
log4j.logger.DataNucleus.Lifecycle       = WARN, A1
log4j.logger.DataNucleus.Cache           = WARN, A1
log4j.logger.DataNucleus.MetaData        = WARN, A1
log4j.logger.DataNucleus.Management      = WARN, A1
log4j.logger.DataNucleus.General         = WARN, A1
log4j.logger.DataNucleus.Connection      = WARN, A1
log4j.logger.DataNucleus.Transaction     = WARN, A1
log4j.logger.DataNucleus.Datastore       = WARN, A1
log4j.logger.DataNucleus.ClassLoading    = WARN, A1
log4j.logger.DataNucleus.Plugin          = WARN, A1
log4j.logger.DataNucleus.ValueGeneration = WARN, A1
log4j.logger.DataNucleus.Enhancer        = WARN, A1
log4j.logger.DataNucleus.SchemaTool      = WARN, A1

<强> logging.properties

handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

[...]

# Set the default logging level for ORM, specifically, to WARNING
DataNucleus.level                 = WARNING
DataNucleus.JDO.level             = WARNING
DataNucleus.Persistence.level     = WARNING
DataNucleus.Query.level           = WARNING
DataNucleus.Lifecycle.level       = WARNING
DataNucleus.Cache.level           = WARNING
DataNucleus.MetaData.level        = WARNING
DataNucleus.Management.level      = WARNING
DataNucleus.General.level         = WARNING
DataNucleus.Connection.level      = WARNING
DataNucleus.Transaction.level     = WARNING
DataNucleus.Datastore.level       = WARNING
DataNucleus.ClassLoading.level    = WARNING
DataNucleus.Plugin.level          = WARNING
DataNucleus.ValueGeneration.level = WARNING
DataNucleus.Enhancer.level        = WARNING
DataNucleus.SchemaTool.level      = WARNING

logger.fatal(“App Error”);

我从未编写过Log4J。这个命令不只是在致命级别记录文本"App Error"的条目吗?

享受?