在 weblogic 9/10 中使用 log4j 日志记录
在 weblogic 中,我可以在控制台中配置 Serverlog 使用 log4j 而不是默认的 JDK 日志记录。
但是,serverlog 没有使用 log4j.properties 文件,但似乎使用 config.xml 中的配置 即使 log4j.properties 文件位于类路径中并且我设置了这些属性:
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dlog4j.configuration=file:<path>/log4j.properties
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.log.Log4jLoggingEnabled=true
是否可以使用 log4j.properties 配置进行 Weblogic Server 日志记录,或者我只能使用 java 代码更改 log4j 配置吗?
In weblogic I can configure in the console for the Serverlog to use log4j instead of default JDK logging.
However the serverlog is not using a log4j.properties file, but seems to use the configuration in config.xml
Even if the log4j.properties file is in the classpath and I set these properties:
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dlog4j.configuration=file:<path>/log4j.properties
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.log.Log4jLoggingEnabled=true
Is it possible to use log4j.properties configuration for Weblogic Server Logging, or can I only change the log4j configuration with java code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我对WebLogic一无所知,但是添加
-Dlog4j.debug
将使log4j告诉您它在哪里寻找其配置。 我发现这在以前跟踪 tomcat 中的日志记录问题时非常有用。查看 PropertyConfigurator 和 DOMConfigurator 了解有关 log4j 配置过程的详细信息。
I don't know anything about WebLogic in particular, but adding
-Dlog4j.debug
will cause log4j to tell you where it's looking for its configuration. I've found that to be invaluable when tracking down logging issues in tomcat previously.Check out the docs for PropertyConfigurator and DOMConfigurator for details on the log4j configuration process.
如果您将 log4j.xml 放入类路径中,WebLogic 将拾取它。 我在 WebLogic 中使用 Apache Commons 日志记录和 log4j,这很容易做到。 不需要那些 Java 选项。
If you put the log4j.xml in your classpath, WebLogic will pick it up. I use Apache Commons logging with log4j in WebLogic, and it's an easy thing to do. No need for those Java options.
您在哪里设置上述选项? 尝试将 -Dlog4j 选项放入将使用 log4j 的每个托管服务器的“服务器启动”选项中
Where are you setting the above options? Try putting the -Dlog4j option in the Server Start options for each managed server that will use log4j
要指定记录到 Log4j 记录器而不是默认的 Java 记录:
来自: http://edocs.bea.com/wls/docs103/logging/config_logs.html#wp1014610
To specify logging to a Log4j Logger instead of the default Java Logging:
From: http://edocs.bea.com/wls/docs103/logging/config_logs.html#wp1014610
我从来没有按照我的意图进行这项工作。
我最终所做的是创建某种解决方法。
我注册了一个监听 Weblogic 服务器日志的处理程序。
我从这个处理程序中将自己的日志记录到 log4j。 该日志记录可以重定向以执行我想要的任何操作。
创建自定义 logHandler:
然后创建 ApplicationLifecycleListener。
使用 postStart 方法:
I never got this working as I intented.
What I eventually did was create some kind of work-around.
I register a Handler that listens to the Weblogic serverlog.
From this handler I do my own logging to log4j. That logging can be redirected to do anything I want.
create a custom logHandler:
then create an ApplicationLifecycleListener.
with a postStart method: