English 中文(简体)
Hibernate JPA 实体管理协会创建额外日志4j投稿人吗?
原标题:Hibernate JPA EntityManager creates extra log4j appender?

我撰写了一份简便灯,利用日本邮局连接MySQL数据库。 实际阅读/撰写数据的工作正在进行,但伐木似乎正在改观。 每个实体 经理认为,我创建的似乎是把自己的记录4j发送到青少年。 因此,由于我有三例实体管理案例,除了我所希望的“再”的产出线外,我还在我们的独角产出中另外增加了三条。 这里就是一个例子。 第1行来自我的“real”发价人,另外3条似乎来自实体管理者:

08:31:58,970 com.electricgearbox.app.ProcessDataItemApp DEBUG main foobar:169 - geoEntityDao.getByCompositeKey took 81 milliseconds 
0 [main] DEBUG foobar  - geoEntityDao.getByCompositeKey took 81 milliseconds 
0 [main] DEBUG foobar  - geoEntityDao.getByCompositeKey took 81 milliseconds 
0 [main] DEBUG foobar  - geoEntityDao.getByCompositeKey took 81 milliseconds 

Here is my log4j configuration:

log4j.rootCategory=WARN, mylog

log4j.appender.mylog=org.apache.log4j.ConsoleAppender
log4j.appender.mylog.layout=org.apache.log4j.PatternLayout
log4j.appender.mylog.layout.ConversionPattern=%d{ABSOLUTE} %C %5p %t %c{2}:%L - %m%n

log4j.category.foobar=DEBUG

我希望能够扭转这一行为,并刚刚达到我所希望的ole线。 我似乎无法就如何这样做“打破法典”,任何帮助都会受到赞赏。

Additional information: It appears that there are two things going on here. The first is the log4j appender additivity setting, which is true by default. Re-reading the sparse log4j documentation (http://logging.apache.org/log4j/1.2/manual.html) I came across this:

Each enabled logging request for a given logger will be forwarded to all the appenders in that logger as well as the appenders higher in the hierarchy.

NOT提到的情况是,无论在等级上确定较高的记录,它显然都会这样做。

就我而言,这意味着或似乎意味着,虽然我的原体记录被定在WARN,但德国马克公司一级的信息仍在使用Hibernate各年级所附的投射器。 这是我所期望的恰恰相反。 我不敢肯定,这是否代表了Hibernate 4.0.1 JPA的实施工作,或者仅仅表明原木4j缺乏文件,或是标志4j和高尔夫4j(由Hibernate使用)之间的 gl。

The second thing that s going on is that every time you create an EntityManager object, it seems to add an appender to your log4j logging tree, so if you have multiple EntityManagers, you get multiple logging messages. This I m pretty sure is a bug in the Hibernate logging.

Still looking for an explanation or an example of how this "additivity" works in practice with log4j - it seems to be working in the reverse of what I would expect from the limited documentation. That is, appenders seem to be passed DOWN the logging tree instead of logging events being passed UP.

Here is what I have so far for my (revised) log4j properties file, and it appears to be working:

log4j.rootCategory=WARN, mylog

# logger "root" logs at WARN level to appender "mylog"
log4j.appender.mylog=org.apache.log4j.ConsoleAppender
log4j.appender.mylog.layout=org.apache.log4j.PatternLayout

# Logger "foobar" logs at DEBUG level to appender "bootylog"
log4j.category.foobar=DEBUG, bootylog

log4j.appender.bootylog=org.apache.log4j.ConsoleAppender
log4j.appender.bootylog.layout=org.apache.log4j.PatternLayout
log4j.appender.bootylog.layout.ConversionPattern=%d{ABSOLUTE} %C %5p %t %c{2}:%L - %m%n

# additivity is off
log4j.additivity.foobar=false
log4j.additivity.org.hibernate=false

这给我带来了以下产出,这正是我想要的:

11:15:43,622 com.electricgearbox.app.ProcessDataItemApp DEBUG main foobar:152 - geoDataItemDao.create took 5 milliseconds 
11:15:43,624 com.electricgearbox.app.ProcessDataItemApp DEBUG main foobar:166 - geoEntityDao.getByCompositeKey took 2 milliseconds 
11:15:43,626 com.electricgearbox.app.ProcessDataItemApp DEBUG main foobar:159 - dataEntityDao.getDataEntityByFieldCode took 1 milliseconds 

Finally, I highly recommend to anyone who is having problems with log4j that they turn on this command line option when they run their app:

-Dlog4j.debug 
最佳回答

这里似乎有两点。 第一种是记录4j 添加剂的设定,这是违约情况。 重读Sparselog4j文件(http://logging.apache.org/log4j/1.2/manual.html) 我来到这里:

Each enabled logging request for a given logger will be forwarded to all the appenders in that logger as well as the appenders higher in the hierarchy.

NOT提到的情况是,无论在等级上确定较高的记录,它显然都会这样做。

就我而言,这意味着或似乎意味着,虽然我的原体记录被定在WARN,但德国马克公司一级的信息仍在使用Hibernate各年级所附的投射器。 这是我所期望的恰恰相反。 我不敢肯定,这是否代表了Hibernate 4.0.1 JPA的实施工作,或者仅仅表明原木4j缺乏文件,或是标志4j和高尔夫4j(由Hibernate使用)之间的 gl。

接下来的第二点是,每当你制造一个实体管理项目时,似乎都会在你伐木树上添加一个信标,这样,如果你拥有多个实体管理者,你就会获得多个伐木信息。 这颗Im 巨型树脂是Hibernate伐木的ug。

还是寻找一个解释或实例,说明这种“额外性”在实际中如何与原木4j发生作用,这似乎正在扭转我对有限文件的期望。 这就是说,伐木树似乎通过DOWN,而不是通过UP的伐木活动。

这里是我迄今为止对我的(经修改的)原木4j财产档案所做的事,似乎正在开展工作:

log4j.rootCategory=WARN, mylog

# logger "root" logs at WARN level to appender "mylog"
log4j.appender.mylog=org.apache.log4j.ConsoleAppender
log4j.appender.mylog.layout=org.apache.log4j.PatternLayout

# Logger "foobar" logs at DEBUG level to appender "bootylog"
log4j.category.foobar=DEBUG, bootylog

log4j.appender.bootylog=org.apache.log4j.ConsoleAppender
log4j.appender.bootylog.layout=org.apache.log4j.PatternLayout
log4j.appender.bootylog.layout.ConversionPattern=%d{ABSOLUTE} %C %5p %t %c{2}:%L - %m%n

# additivity is off
log4j.additivity.foobar=false
log4j.additivity.org.hibernate=false

这给我带来了以下产出,这正是我想要的:

11:15:43,622 com.electricgearbox.app.ProcessDataItemApp DEBUG main foobar:152 - geoDataItemDao.create took 5 milliseconds 
11:15:43,624 com.electricgearbox.app.ProcessDataItemApp DEBUG main foobar:166 - geoEntityDao.getByCompositeKey took 2 milliseconds 
11:15:43,626 com.electricgearbox.app.ProcessDataItemApp DEBUG main foobar:159 - dataEntityDao.getDataEntityByFieldCode took 1 milliseconds 

最后,我高度建议,凡在标志4j问题上有问题的人,在他们执政时,他们选择这一指挥线:

-Dlog4j.debug 
问题回答




相关问题
Best logging approach for composite app?

I am creating a Composite WPF (Prism) app with several different projects (Shell, modules, and so on). I am getting ready to implement logging, using Log4Net. It seems there are two ways to set up the ...

How to make logging.debug work on Appengine?

I m having a tough time getting the logging on Appengine working. the statement import logging is flagged as an unrecognized import in my PyDev Appengine project. I suspected that this was just an ...

How to validate Java logging properties files?

I have a basic facility for allowing users to remotely apply changes to the logging files in my application. Some logs are configured using java.util.logging properties files, and some are configured ...

Logging SAS scripts

I ve been developing a lot of Java, PHP and Python. All of which offer great logging packages (Log4J, Log or logging respectively). This is a great help when debugging applications. Especially if the ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

热门标签