我撰写了一份简便灯,利用日本邮局连接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