在 weblogic 9/10 中使用 log4j 日志记录

发布于 2024-07-14 04:56:38 字数 566 浏览 4 评论 0原文

在 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 技术交流群。

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

发布评论

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

评论(5

葬心 2024-07-21 04:56:38

我对WebLogic一无所知,但是添加-Dlog4j.debug将使log4j告诉您它在哪里寻找其配置。 我发现这在以前跟踪 tomcat 中的日志记录问题时非常有用。

查看 PropertyConfiguratorDOMConfigurator 了解有关 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.

偏闹i 2024-07-21 04:56:38

如果您将 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.

南…巷孤猫 2024-07-21 04:56:38

您在哪里设置上述选项? 尝试将 -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

感情废物 2024-07-21 04:56:38

要指定记录到 Log4j 记录器而不是默认的 Java 记录:

* When you start the Administration Server, include the following Java option in the weblogic.Server command:

  -Dweblogic.log.Log4jLoggingEnabled=true 

来自: http://edocs.bea.com/wls/docs103/logging/config_logs.html#wp1014610

To specify logging to a Log4j Logger instead of the default Java Logging:

* When you start the Administration Server, include the following Java option in the weblogic.Server command:

  -Dweblogic.log.Log4jLoggingEnabled=true 

From: http://edocs.bea.com/wls/docs103/logging/config_logs.html#wp1014610

睡美人的小仙女 2024-07-21 04:56:38

我从来没有按照我的意图进行这项工作。

我最终所做的是创建某种解决方法。
我注册了一个监听 Weblogic 服务器日志的处理程序。
我从这个处理程序中将自己的日志记录到 log4j。 该日志记录可以重定向以执行我想要的任何操作。

创建自定义 logHandler:

public class CustomLogHandler extends Handler {
..

    public CustomLogHandler () throws SecurityException, IOException,
            NamingException {

        String log4jConfig = LogFilterConfiguration.getLog4jDirectory();
        classlogger.info("log4j configured for file"+ log4jConfig );
        PropertyConfigurator.configure(log4jConfig);
        logFilterConfiguration = new LogFilterConfiguration();
    }

    public void publish(LogRecord record) {
        WLLogRecord rec = (WLLogRecord) record;
        if (!isLoggable(rec))
            return;
        if (getLoggerName().. is something i want to log) {
                        // do my own log4j logging
                  }

然后创建 ApplicationLifecycleListener。
使用 postStart 方法:

public void postStart(ApplicationLifecycleEvent evt) {
    Logger logger = LoggingHelper.getServerLogger();
    Handler oldHandler = null;
    Handler[] currentHandlers = logger.getHandlers();

              .. code to remove an old custom handler if exists...
    with something like logger.removeHandler(oldHandler);

    // add custom handler to serverlogger.
    CustomLogHandler h = null;      
    try {
        h = new CustomLogHandler ();
        // If handler was removed we can add a new version.
        if (!(unRemovedHandlerClasses.contains(h.getClass()))){
            logger.addHandler(h);
            registerMBean(h) ;
        }
    } catch (Exception nmex) {
    classLogger.error("Error adding CustomLogHandler to serverlogger "
                + nmex.getMessage());
        logger.removeHandler(h);
    }


}

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:

public class CustomLogHandler extends Handler {
..

    public CustomLogHandler () throws SecurityException, IOException,
            NamingException {

        String log4jConfig = LogFilterConfiguration.getLog4jDirectory();
        classlogger.info("log4j configured for file"+ log4jConfig );
        PropertyConfigurator.configure(log4jConfig);
        logFilterConfiguration = new LogFilterConfiguration();
    }

    public void publish(LogRecord record) {
        WLLogRecord rec = (WLLogRecord) record;
        if (!isLoggable(rec))
            return;
        if (getLoggerName().. is something i want to log) {
                        // do my own log4j logging
                  }

then create an ApplicationLifecycleListener.
with a postStart method:

public void postStart(ApplicationLifecycleEvent evt) {
    Logger logger = LoggingHelper.getServerLogger();
    Handler oldHandler = null;
    Handler[] currentHandlers = logger.getHandlers();

              .. code to remove an old custom handler if exists...
    with something like logger.removeHandler(oldHandler);

    // add custom handler to serverlogger.
    CustomLogHandler h = null;      
    try {
        h = new CustomLogHandler ();
        // If handler was removed we can add a new version.
        if (!(unRemovedHandlerClasses.contains(h.getClass()))){
            logger.addHandler(h);
            registerMBean(h) ;
        }
    } catch (Exception nmex) {
    classLogger.error("Error adding CustomLogHandler to serverlogger "
                + nmex.getMessage());
        logger.removeHandler(h);
    }


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