论坛首页 Java版 Hibernate

log4j.properties的问题

浏览 7513 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2004-12-30
log4j的机制很强大,我现在遇到一个问题,我做了一个war发布到tomcat上,可以正常显示,也能根据log4j.properties的配置信息生成一个log文件,但我把这个发布到jboss上,就不能读取到log4j.properties了,原因是jboss内部的日志信息就是log4j.它通过一个log4j.xml配置文件能把容器内的所有log信息放到指定的文件中,但是问题是我想用war文件内的logrj.properties.不想用容器的log4j.xml.
不好意思,说得有一点啰嗦,总而言之,我想在jboss上使用某个war文件的log4j.properties.生成一个log文件,如何实现。
   
最后更新时间:2004-12-30
这个问题我也碰到过,最后我是在JBOSS的xml文件中自己写了一段进去实现的。用自己的project的我也没有试出来。有经验的朋友介绍一下吧。
   
0 请登录后投票
最后更新时间:2004-12-30
我的经验是不要定义ROOT  Logger, 而是定义你自己的顶层 Logger, 例如:

(假设你所有的包都以 "com.microsoft" 开头)
log4j.logger.com.microsoft=DEBUG, stdout, logfile
log4j.additivity.com.microsoft=false

......(其它的没什么两样)
   
0 请登录后投票
最后更新时间:2004-12-31
to downpour:你在log4j.xml写的那一段配置是不是生成文件中也包含了jboss的log信息呢,是不是没有办法实现在某个log日志中显示某一个APP的所有信息。
to glassprogrammer :你的意思是要把这两句加在log4j.xml里,还是加在log4j.properties中呢,如果放在log4j.properties中,那么怎么通过jboss读取这个信息。
如果要放在log4j.xml中,这个应该怎么写,还有就是log4j.additivity.com.microsoft=false
这句是什么意思?
   
0 请登录后投票
最后更新时间:2004-12-31
上面那个是 log4j.properties 中的部分内容, 干脆给你全部的吧:
[code:1]
#Global variable definition
LOG_LEVEL=DEBUG
LOG_FILE=/microsoft.log

# com.microsoft Logger
log4j.logger.com.microsoft=${LOG_LEVEL}, stdout, logfile
log4j.additivity.com.microsoft=false

# Console Appender Definition
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p %c(%t) %x:%m%n
#log4j.appender.stdout.layout.ConversionPattern=%-5p:[%d{MM/dd HH:mm:ss,SSS}] %c(%t) %x:%m%n

# File Appender Definition
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.File=${LOG_FILE}
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%-5p:[%d{ISO8601}] %c(%t) %x:%m%n
[/code:1]

log4j.properties 只需要放到你的 classpath 中就可以了, 对于 war, 你可以放到 WEB-INF/classes/

log4j.additivity.com.microsoft=false 说明 com.microsoft 这个 Logger 的 appender 不继承它的父Logger(在这里, 是 com Logger 和 ROOT Logger), 目的是防止jboss那个xml中定义的ROOT Logger和我们这个log4j.properties中定义的Logger互相干扰.
引用
# Beware that appenders are not singletons, they are additive! A category inherits all the appenders from its ancestors also (by default). If you add an appender to a category and it writes to the same underlying stream (console, same file etc.) as some other appender, the same log message will appear twice (or more) in the log. In addition, if two categories in a hierarchy are configured to use the same appender name, Log4j will write twice to that appender. Use cat.setAdditivity(false) on a category to disable inheriting of appenders. Then, log messages will only be sent to the appenders specifically configured for that category. 
   
0 请登录后投票
最后更新时间:2004-12-31
感谢glassprogrammer,
我的问题已经解决了,按照你的思路,我在jboss.xml上做了一点修改,意思跟你说的差不多,不过,不是读取log4j.properties文件,而是把想要的东西在log4j.xml实现了,真的很感谢你。如果有需要,我可以把我修改后的log4j.xml贴出来。不过,美中不足的就是不知道,如何通过jboss的配置文件使每个war文件自带的log4j.properties生效。希望有这方面经验的朋友指教一二。
   
0 请登录后投票
最后更新时间:2005-06-23
LIMIMGJIE 写道
感谢glassprogrammer,
我的问题已经解决了,按照你的思路,我在jboss.xml上做了一点修改,意思跟你说的差不多,不过,不是读取log4j.properties文件,而是把想要的东西在log4j.xml实现了,真的很感谢你。如果有需要,我可以把我修改后的log4j.xml贴出来。不过,美中不足的就是不知道,如何通过jboss的配置文件使每个war文件自带的log4j.properties生效。希望有这方面经验的朋友指教一二。


帖出来吧,我实在配制不成,请指点。我谢啦
   
0 请登录后投票
论坛首页 Java版 Hibernate

跳转论坛:
JavaEye推荐