如果不进行优化配置,JBOSS下的项目查错将非常麻烦,在JBOSS4.2.2GA版本中,默认将所有的DEBUG信息都输了个遍,刚运行JBOSS,Server.log的日志就差不多1M了,再停掉JBOSS,什么正事都没做,都己经生成看不到的LOG了,只能用一个字来形容:费物!
不过话先别说得这么激,年轻人,应该控制好自己的心态,冲动是魔兽咧!LOG太多确实一点用也没有,本来这些LOG最大的功能是方便查错的,但如果生成N行的LOG,从中找到你想要的,我还不如把程序检查一遍算了!因此,在不同的应用场合下,配置好你的LOG,才能让项目更加顺利地进行哦!
好了,转入正题,本文针对的是JBOSS4的LOG4J配置,其它的请参阅相应的文章。
JBOSS4的LOG4J配置默认放在Deploy目录的conf/目录下,比如现在我将ear放到jboss的default目录下,那么log4j的文件就是jboss/server/default/conf/jboss-log4j.xml,找到它,我们再分析一下它里面的内容吧。
首先是第一段,一个FILE的appender,代码如下
- <!-- A time/date based rolling appender -->
- <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
- <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
- <param name="File" value="${jboss.server.log.dir}/server.log"/>
- <param name="Append" value="false"/>
- <!-- Rollover at midnight each day -->
- <param name="DatePattern" value="'.'yyyy-MM-dd"/>
- <!-- Rollover at the top of each hour
- <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
- -->
- <layout class="org.apache.log4j.PatternLayout">
- <!-- The default pattern: Date Priority [Category] Message/n -->
- <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
- <!-- The full pattern: Date MS Priority [Cate