使用 JBOSS5 进行 Log4j 日志记录

发布于 2024-09-27 16:20:17 字数 1070 浏览 0 评论 0 原文

我在我的应用程序中使用 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晌融 2024-10-04 16:20:17

很可能您的 log4j.properties 没有被获取。

要在 Jboss 5 中配置 log4j,您可以编辑以下文件:

server/default/conf/jboss-log4j.xml

如果您仍想使用 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

server/default/conf/jboss-log4j.xml

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文