Log4J不记录任何内容 [英] Log4J does not log anything

查看:111
本文介绍了Log4J不记录任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在工作时选择了一个现有的Web应用程序,该应用程序应该使用Log4J记录其活动.我已经按照告诉我的方式完全配置了工作空间,其他所有内容(数据库连接,身份验证等)都可以正常工作,只是没有任何内容被写入日志文件.其他类似的应用程序没有问题记录.

I just picked up an existing web application at work that is supposed to log its activity using Log4J. I've configured my workspace exactly as I was told to and everything else (db connection, authentication, etc...) works fine except that the nothing is being written to the log file. Other similar applications have no problem logging.

我已经在应用程序启动时查看了WebSphere控制台,并且那里没有错误可能表明Log4J不进行记录的原因.

I've looked at the WebSphere console when the application starts up and there are no errors there that might indicate why Log4J isn't logging.

我向另一个开发人员提到了这一点(该开发人员曾经从事过此应用程序,但工作了一段时间,但比我现在过时的过时了),他说这是非常奇怪的行为,但不知道为什么会这样无法记录日志并且不报告任何错误.

I mentioned this to another dev (who once worked on this application, but not for a while and is more out of date than I am on it) who remarked that it was very strange behaviour, but had no idea why it might fail to log and not report any errors.

我已经查看了配置文件和属性文件,一切看起来都很正常.我怀疑Log4J甚至从未读取过log4j.xml,但我不确定.自从我使用Log4J以来已经有一段时间了-有人在解决此类问题时有一些不错的提示吗?

I've gone over the config file and properties file and everything looks OK. I suspect that Log4J is never even reading the log4j.xml but I'm not certain of that. It's been a while since I've worked with Log4J - does anyone have some good tips on trouble-shooting this type of problem?

PS:此应用程序的某些实例已部署到各种测试/QA/产品服务器,并且这些实例均正常运行.在本地工作站上,唯一日志记录似乎默默地失败了.

PS: There are instances of this application that are deployed to various test/QA/prod servers and these instances all log fine. It's only on local workstations that logging seems to silently fail.

更新:因此,部署应用程序的方式似乎确实存在问题. 我将类加载器模式更改为"Parent Last",并且可以看到至少现在正在读取Log4J文件.我尝试执行的第一个操作会触发一个ClassNotFoundException,说无法找到org.apache.commons.logging.impl.Log4jFactory.

Update: So it does seem to be a problem with the way the application is being deployed. I changed the classloader mode to "Parent Last" and I can see that the Log4J file is at least being read now. And the first action I attempt triggers a ClassNotFoundException saying that org.apache.commons.logging.impl.Log4jFactory cannot be found.

第二次更新: 我注意到了一些奇怪的事...该应用程序有两个WAR项目-其中一个用于UI,另一个用于某些Web服务.用于UI 的项目已成功将其操作记录到日志文件中. Web服务项目是失败的ClassNotFoundException项目.它们都具有被列为JavaEE模块依赖项的commons-logging.jar,并且都没有特定于项目的日志记录配置(所有配置文件都在Resources项目中).

2nd Update: I've noticed something stranger... The application has two WAR projects - one of them is for the UI and the other is for some web services. The project that is for the UI is successfully logging its operations to the log file. The web service project is the one that fails with the ClassNotFoundException. Both of them have commons-logging.jar listed as a JavaEE module dependency, and neither of them have a project-specific logging configuration (all config files are in a Resources project).

主要区别在于,UI项目包括一些其他内部框架(预编译为JAR),可能已经包含必要的日志记录配置,也许就是这些地方.

A major difference is that that UI project includes some other in-house frameworks (pre-compiled as JARs) that might already include necessary logging configurations and maybe that's where the difference is.

我还尝试使用答案(来自META-INF/services中名为org.apache.commons.logging.LogFactory的文件,其中一行包含:"org.apache.commons.logging.impl.Log4jFactory")这个问题: Websphere所有日志都将转到SystemOut.log ,但似乎没有帮助.

I also tried to use the answer (a file named org.apache.commons.logging.LogFactory in the META-INF/services with one line containing: "org.apache.commons.logging.impl.Log4jFactory") from this question: Websphere all logs are going to SystemOut.log but it did not seem to help.

推荐答案

我所做的最后更改使日志正常运行,这是我更改的最新内容是将类加载器模式更改为"PARENT_FIRST",并将WAR类加载器策略更改为应用程序".初始默认配置为"PARENT_FIRST"/模块".我根据一位同事的建议将其更改为"PARENT_LAST"/应用程序",他说日志记录对他们来说很好用,这是他们为该应用程序创建新沙箱时唯一要做的更改.我不确定为什么必须使用"PARENT_FIRST"/应用程序",但至少现在可以使用.

The most recent thing I changed that finally got logging working properly was changing the classloader mode to "PARENT_FIRST" and WAR classloader policy to "Application". The initial default configuration was "PARENT_FIRST"/"Module". I changed it to "PARENT_LAST"/"Application" on the advice of a co-worker who says logging works fine for them and this is the only change they have to make when they create a new sandbox for this application. I'm not sure why I had to go with "PARENT_FIRST"/"Application", but at least it works now.

更新:

我尝试设置一个新的工作区,但遇到了同样的问题.事实证明,您需要"PARENT_FIRST"/应用程序"以及META-INF/services中一个名为org.apache.commons.logging.LogFactory的文件,其中包含以下行:"org.apache.commons.logging.impl.Log4jFactory" .没有该文件会导致记录失败(通常会显示一条消息,指出找不到Log4J).

I tried setting up a new workspace and I had the same problem. It turns out you need "PARENT_FIRST"/"Application" AND a file named org.apache.commons.logging.LogFactory in the META-INF/services with one line containing: "org.apache.commons.logging.impl.Log4jFactory". Not having the file causes logging to fail (typically with a message saying that a Log4J cannot be found).

这篇关于Log4J不记录任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆