log4j 不能在 weblogic 服务器上工作?
我正在使用 weblogic 10.3.4,我正在尝试使用 log4j 写入日志。但在运行时我的应用程序没有获得任何 log4j.properties。即使这样也不会生成任何警告,因为“log4j 的初始化有错误”。
我尝试将属性文件放入 src 文件夹、classes 文件夹,然后创建一个 jar 并将其放入域 lib 中。仍然没有采摘。即使当我在独立应用程序中使用相同的 jar 编写日志时,它也工作正常。
请帮助我提出宝贵的建议。
I am using weblogic 10.3.4, I am trying to write log with log4j. but at runtime my application is not getting any log4j.properties. even this is not generating any warning as "initialization of log4j has error".
I have tried my properties file to put in src folder, classes folder and then I created one jar and put it in domain lib. still its not picking. even when I am writing log with same jar in standalone application, its working fine.
please help me with valuable suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我尝试了 Oracle 论坛上提出的解决方案。
摘自 Oracle 论坛上的链接:
我只修改了脚本 startWebLogic.cmd:
通过这种方式,我将所有配置文件夹放入类路径中,将来可以使用它来保存其他库配置文件(例如 oracle coherence config)。
我也在不同的属性文件上尝试了这种方法,效果很好!
I tried the solution proposed at Oracle forums.
Excerpt from that link at Oracle forums:
I've only modified the scritp startWebLogic.cmd:
In this way I've put all the config folder inside the classpath, and I can use it in future to hold other libraries configuration files (for example oracle coherence config).
I tried this approach on a different properties file as well and that worked well!
您需要指定应用程序应在何处找到其 log4j.properties,或将其放入应用程序的类路径中。类路径的位置各不相同,但一般来说 WEB-INF/classes 应该可以工作。其他选项取决于您部署应用程序的方式。
更好的长期策略是配置您的系统,以便您可以根据环境更改 log4j.properties。当您在生产中时,您不会希望显示所有调试信息。查看 这个问题或这个问题了解更多想法。一种策略是在命令行上定义一个变量,该变量会被拾取并定义一个包含配置文件的目录。这适用于 Tomcat,但对于 Weblogic 可能还有其他更好的策略。
更改服务器的配置不是一个好主意,特别是不要替换服务器目录中的 log4j.jar 或 log4j.properties。服务器将取决于它设计使用的版本,该版本可能与您的版本相同,也可能不同。你可以通过改变你正在部署的战争来完成你需要做的一切。
You need to either specify where the application should find its log4j.properties, or put it onto the classpath of the application. Where the classpath is varies, but in general WEB-INF/classes should work. Other options depend upon how you're deploying the application.
A better long term strategy is to configure your system so that you can change the log4j.properties depending upon the environment. When you're in production, you won't want all of the debug information to appear. Look at the answer to this question or this question for more ideas. One strategy is to define a variable on the command line which gets picked up and defines a directory which contains your configuration files. This works for Tomcat, but there may be other, better, strategies for Weblogic.
It is not a good idea to change the configuration of your server, in particular, don't replace the log4j.jar or log4j.properties in your server directories. The server will depend upon the version that it was designed to use, which may or may not be the same as your version. You can do everything you need to do by changing the war that you're deploying.
我使用了这段代码:
在我的例子中,我们使用了 XML 配置:
在 WebLogic 中,我们能够将这样的文件 (mylog4j.xml) 放置在 WebLogic 的域路径(特定于我们所在的域)中,该文件相当于您的 log4j.properties 文件部署)。这意味着域文件夹属于您的应用程序的路径。我刚刚用 Web 应用程序测试了它,我不确定在 SOA 或 EJB 项目中它的工作方式是否相同。
I have used this code:
In my case, we used XML configuration:
In WebLogic, we were able to place such file (mylog4j.xml), equivalent to your log4j.properties file, at WebLogic's domain path (specific to the domain were we deploy). This means that domain folder belongs to your application's path. I just tested it with Web applications, I'm not sure if with SOA or EJB projects it works the same way.
当您在任何服务器上部署任何应用程序时,该应用程序应该使用服务器 log4j jar。
因此,如果您在应用程序 jar/tar/ear 中添加了任何 log4j jar,请将其删除并将 log4j.properties 文件复制到服务器的 conf 文件夹中,服务器从中选择其配置文件。或者只需将 log4j 属性内容复制到服务器 log4j 属性文件中。
When you deploy any application on any server that application should use servers log4j jar.
So if you have added any log4j jar in your application jar/tar/ear, remove it and copy log4j.properties file in the conf folder of the server from where server is picking its configuration files. Or just copy your log4j property content in servers log4j property file.