如何更改Weblogic 10/11的日志格式?

发布于 2024-08-19 10:30:35 字数 1139 浏览 9 评论 0原文

我想更改Weblogic服务器日志的日志格式。现在它正在使用默认格式生成日志——我希望能够指定我自己的格式。

例如,它生成如下所示的日志:

####<Jan 21, 2010 3:24:24 PM EST> <Info> <Socket> <FS2LOANER-00981> <DPSCoreServer1> <[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1264105464314> <BEA-000436> <Allocating 2 reader threads.> 
####<Jan 21, 2010 3:24:24 PM EST> <Info> <Socket> <FS2LOANER-00981> <DPSCoreServer1> <[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1264105464314> <BEA-000446> <Native IO Enabled.> 

我尝试通过让 Weblogic 使用 LOG4J 作为其日志记录系统并让它使用定义我所需日志格式的 log4j.properties 文件来修改日志格式。但是,无论我尝试什么,weblogic 都不会获取我的 log4j.property 文件设置并继续以其所需的格式进行登录。

这实际上是与以下帖子非常相似的问题,但该问题从未真正得到解答(批准的答案是关于如何打开 log4j 调试,这并没有帮助我弄清楚为什么 weblogic 没有获取我的 log4j.properties文件)。 在 weblogic 9/10 中使用 log4j 日志记录

I want to change the log format for Weblogic's server log. Right now it's generating logs using its default format-- I want to be able to specify my own format.

For example, it generates logs that look like this:

####<Jan 21, 2010 3:24:24 PM EST> <Info> <Socket> <FS2LOANER-00981> <DPSCoreServer1> <[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1264105464314> <BEA-000436> <Allocating 2 reader threads.> 
####<Jan 21, 2010 3:24:24 PM EST> <Info> <Socket> <FS2LOANER-00981> <DPSCoreServer1> <[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1264105464314> <BEA-000446> <Native IO Enabled.> 

I have tried to modify the log format by having Weblogic use LOG4J as its logging system and having it use my log4j.properties file which defines my desired log formats. However, weblogic does not pick up my log4j.property file settings and continues to log in its desired format, regardless of what I try.

This is effectively a very similar question to the following post, but that question never really got answered (the approved answer was regarding how to turn on log4j debugging, which hasn't helped me figure out why weblogic is not picking up my log4j.properties file). Using log4j logging in weblogic 9/10

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

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

发布评论

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

评论(5

简美 2024-08-26 10:30:35

创建域启动类如下:

import org.apache.log4j.PatternLayout;

import weblogic.logging.LoggerNotAvailableException;
import weblogic.logging.log4j.Log4jLoggingHelper;

public class LoggingConfigurator {
    public static void main(String[] args) {
        try {
            System.out.println("Configuring Log4j pattern");
            Log4jLoggingHelper.getLog4jServerLogger().getAppender("WLLog4jRotatingFileAppender")
                    .setLayout(new PatternLayout("%d{ISO8601} %-5p [%c] - %m%n"));
        } catch (LoggerNotAvailableException e) {
            e.printStackTrace();
        }
    }
}

Amnon

Create a domain startup class as follows:

import org.apache.log4j.PatternLayout;

import weblogic.logging.LoggerNotAvailableException;
import weblogic.logging.log4j.Log4jLoggingHelper;

public class LoggingConfigurator {
    public static void main(String[] args) {
        try {
            System.out.println("Configuring Log4j pattern");
            Log4jLoggingHelper.getLog4jServerLogger().getAppender("WLLog4jRotatingFileAppender")
                    .setLayout(new PatternLayout("%d{ISO8601} %-5p [%c] - %m%n"));
        } catch (LoggerNotAvailableException e) {
            e.printStackTrace();
        }
    }
}

Amnon

比忠 2024-08-26 10:30:35

据我所知,您不能(不,您不想)更改WebLogic Server自己的日志消息格式(支持人员将非常乐意在出现问题时提供所需的信息)。

但您可以将 WebLogic 配置为使用 Log4j(请参阅 如何将 Log4j 与 WebLogic 日志记录服务结合使用),并且当启用 Log4j 时,您可以获得对服务器正在使用的 org.apache.log4j.Logger 的引用并附加您自己的附加器。

启用 Log4j 后,您会得到
参考
org.apache.log4j.Logger 表示
服务器正在使用来自
weblogic.logging.log4j.Log4jLoggingHelper
类。

通过 Log4j Logger 参考,您可以
将您自己的自定义附加程序附加到
接收服务器日志事件;为了
例如,您可以附加一个附加程序
将服务器日志事件发送到
Syslog 或 Windows 事件查看器。
此外,您还可以使用记录器
参考发出日志请求
WebLogic 日志服务;这
要求 Log4j 库是
可供您部署的
应用程序。

但这并不能替代WebLogic自己的日志。

To my knowledge, you can't (and no, you don't want to) change WebLogic Server's own Log Message Format (the support will be very happy to have the required informations in case of a problem).

But you can configure WebLogic to use Log4j (see How to Use Log4j with WebLogic Logging Services) and, when Log4j is enabled, you can get a reference to the org.apache.log4j.Logger that the server is using and attach your own appender.

When Log4j is enabled, you get a
reference to the
org.apache.log4j.Logger that the
server is using from the
weblogic.logging.log4j.Log4jLoggingHelper
class.

With a Log4j Logger reference, you can
attach you own custom appender to
receive the server log events; for
example, you might attach an appender
that sends the server log events to
Syslog or the Windows Event Viewer.
Additionally, you can use the Logger
reference to issue log requests to
WebLogic logging services; this
requires that the Log4j libraries be
available to your deployed
application.

But this is not a replacement of WebLogic's own log.

葬シ愛 2024-08-26 10:30:35

我无意更换WebLogic的记录器,但我确实有非常强烈的愿望配置日志格式。 Amnon发布的方法效果很好(所以我不知道为什么你说你不能改变格式);我只是想要一些额外的细节。

我在该方法中看到的唯一负面影响是,如果您将 StdOut/StdErr 重定向到日志记录子系统,它会在日志中显示为 %c 转换字符的空值;如果我不改变布局模式,那么我会看到 和 。

就是我想要看到的原始模式布局字符串,这样我就可以进行更改并保留在日志文件中。

I have no desire to replace WebLogic's logger, but I do have a very strong desire to configure the log format. The method Amnon posted works very well (so I'm not sure why you say you can't change the format); I'd just like some additional detail.

About the only negative I see with the method is that, if you have StdOut/StdErr redirected to the logging subsystem, it shows up in the log with an empty value for the %c conversion character; if I don't change the layout pattern then I see and instead.

That is what I wanted to see the original pattern layout string, so I could make my changes and keep in the logfile.

太阳公公是暖光 2024-08-26 10:30:35

到目前为止的帖子没有回答最初的问题,这就是为什么 WebLogic 没有选择 log4j.properties 文件中配置的所需日志格式。

在我看来,您正在使用 WL 的服务器日志记录桥将应用程序的 log4j 消息重定向到 WL 服务器的日志记录服务?如果这个假设是正确的,来自配置日志文件和过滤日志Oracle WebLogic Server 的消息,您需要在 WL 服务器的启动命令中传递一个参数,以加载正确的 log4j 配置,

-Djava.util.logging.config.file=/[PATH]/log4j.properties

Cleaner 只需在启动 WL 时传递此 JVM 选项,不过您也可以像上一篇文章中那样通过编程来实现它。

The posts so far did not answer the original question, which is why WebLogic does not pick up the desired log format configured in log4j.properties file.

It sounds to me that you are using WL's Server Logging Bridge to redirect application's log4j's messages to the WL server's logging services? If this assumption is correct, from Configuring Log Files and Filtering Log Messages for Oracle WebLogic Server, you would need to pass an argument in the WL server's startup command, to load the correct log4j configurations,

-Djava.util.logging.config.file=/[PATH]/log4j.properties

Cleaner just pass this JVM option when you launch WL, though alternatively you can achieve it programmingly as in the previous post.

撩动你心 2024-08-26 10:30:35

Weblogic 没有获取您的 log4j.properties,因为它不知道有一个。

您需要转到服务器的类路径并将路径附加到属性文件,保存更改并重新启动服务器。它应该可以解决问题。

Weblogic is not picking up your log4j.properties because its does not know that there is one.

You need to go to server's classpath and append the path to properties file, save changes and restart your server. It should do the trick.

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