我在我的应用程序中使用 log4j 作为日志记录框架,并使用 JBOSS 5 作为应用程序服务器。我在应用程序的 src 文件夹中创建了一个 log4j.properties 文件。这就是我的 log4j.properties 的样子:
#Default log level to ERROR. Other levels are INFO and DEBUG.
log4j.rootLogger=INFO, ROOT
log4j.appender.ROOT=org.apache.log4j.RollingFileAppender
##Uncomment the next line and comment the 2nd next line when ready to deploy
log4j.appender.ROOT.File=/www/public/logs/myapp.log
##log4j.appender.ROOT.File=C:/myapp.log
log4j.appender.ROOT.MaxFileSize=100KB
#Keep 5 old files around.
log4j.appender.ROOT.MaxBackupIndex=5
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
#Format almost same as WebSphere's common log format.
log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %c %-5p - %m%n
#Optionally override log level of individual packages or classes
log4j.logger.com.webage.ejbs=INFO
但我可以看到 myapp.log 从未创建过,所以我看不到任何日志。我还可以在服务器日志文件夹中保存 server.log 文件,但它非常冗长,很难跟踪那里发生的情况。所以我有两个问题:
1. 为什么myapp.log没有被创建。
2. 你认为上面显示的 log4j.property 文件足够了,还是不需要在这里配置更多的东西。
谢谢,
萨米尔
I am using log4j as logging framework in my application and JBOSS 5 as Application server. I have created a log4j.properties file in the src folder of the application. That's how my log4j.properties looks like:
#Default log level to ERROR. Other levels are INFO and DEBUG.
log4j.rootLogger=INFO, ROOT
log4j.appender.ROOT=org.apache.log4j.RollingFileAppender
##Uncomment the next line and comment the 2nd next line when ready to deploy
log4j.appender.ROOT.File=/www/public/logs/myapp.log
##log4j.appender.ROOT.File=C:/myapp.log
log4j.appender.ROOT.MaxFileSize=100KB
#Keep 5 old files around.
log4j.appender.ROOT.MaxBackupIndex=5
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
#Format almost same as WebSphere's common log format.
log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %c %-5p - %m%n
#Optionally override log level of individual packages or classes
log4j.logger.com.webage.ejbs=INFO
But I can see that the myapp.log is never been created so I am not able to see any logs. Also I can server.log file in the sever logs folder but it has so much verbose that it's hard to track what's going on there. So I have two questions:
1. Why myapp.log is not being created.
2. Do u think the log4j.property file shown above is sufficient or not need to configure more stuff here.
Thanks,
Sameer
发布评论
评论(1)
很可能您的 log4j.properties 没有被获取。
要在 Jboss 5 中配置 log4j,您可以编辑以下文件:
如果您仍想使用 log4j.propeties,在 Web 应用程序中,应将其放置在
deploy/myapp.war/WEB-INF/classes
按照 “10.3.7. 使用您自己的 log4j.properties 文件 - 类加载器作用域” 部分的详细说明进行操作/en/html/logging.html" rel="noreferrer">此链接
Most likely your log4j.properties is not getting picked up.
To configure log4j in Jboss 5 you would edit the file at
If you still want to use log4j.propeties, In the webapp, it should be placed in in your
deploy/myapp.war/WEB-INF/classes
Follow the detailed instuctions at section "10.3.7. Using your own log4j.properties file - class loader scoping" in this link