以与平台无关的方式指定 Websphere 中的日志文件位置

发布于 2024-09-16 19:32:47 字数 145 浏览 1 评论 0原文

在 Websphere 7.0 上使用 Log4J RollingFileAppender 时,如何在 log4j.properties 文件中指定日志记录目录的位置,即获取 Websphere 的 LOG_ROOT 变量?

When using a Log4J RollingFileAppender on Websphere 7.0, how can I specify the location of the logging directory in the log4j.properties file, i.e. pick up Websphere's LOG_ROOT variable?

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

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

发布评论

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

评论(2

各空 2024-09-23 19:32:47

您可以选择指定可以使用 WebSphere 变量的 JVM 自定义属性。

JVM 自定义属性可以在 log4j.properties 中使用。

下面是一些实现相同目标的说明:

在管理控制台中,路径为:

应用程序服务器 > 应用程序服务器 > 应用程序服务器 > 应用程序服务器 > 应用程序服务器 > 应用程序服务器您的服务器名称>流程定义> Java虚拟机>自定义属性

Customer 属性可以使用 WebSphere 变量作为自定义属性 - KeyForMyCustomProperty 的值。 WebSphere 变量将使用标准模式:${}

例如${MY_VARIABLE}

log4j 属性文件可以通过

log4j.appender.messageAppender.File=${KeyForMyCustomProperty}/Message.log

访问此自定义属性。这种方法并不简单,但达到了预期的结果。您可以选择使用与 JVM 自定义属性的 WebSphere 变量相同的键,然后它看起来就好像在 log4j.properties

HTH 中使用了 WebSphere 变量
曼鲁

You have an option of specifying a JVM Custom property which can use the WebSphere variables.

The JVM Custom property can be used in your log4j.properties.

Find below some instructions on achieving the same:

In the admin console the path would be:

Application servers > Your Server Name > Process Definition > Java Virtual Machine > Custom Properties

The Customer property can use a WebSphere variable as the value for our custom property - KeyForMyCustomProperty. The WebSphere variable would use the standard pattern: ${}

E.g ${MY_VARIABLE}.

The log4j properties files could access this custom property via

log4j.appender.messageAppender.File=${KeyForMyCustomProperty}/Message.log

This approach is not straightforward but achieves the desired results. You can choose to use the same key as the WebSphere variable for the JVM Custom Property then it appears as-if the WebSphere variable is used in the log4j.properties

HTH
Manglu

青春有你 2024-09-23 19:32:47

当然,编写 RollingFileAppender 的自定义子类非常简单,该子类以与平台无关的方式以编程方式确定 LOG_ROOT 变量值。

如果是这样的话,它可能只需要大约十几行代码。然后跟进,

    <appender name="CustomAppender" class="path.to.your.CustomAppender">
            <param name="File" value="fileNameOnly.out" />
            <param name="Append" value="true" />
            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="%m%n" />
            </layout>
    </appender>

让子类接受File参数,派生出LOG_ROOT路径,并在调用超类方法之前将其追加到文件名中。

我希望能以某种方式有所帮助,

-gMale

Of course, it would be trivially simple to write a custom subclass of RollingFileAppender that programatically determines the LOG_ROOT variable value, in a platform-independent way.

It would likely only require about a dozen lines of code, if that. Then follow up with,

    <appender name="CustomAppender" class="path.to.your.CustomAppender">
            <param name="File" value="fileNameOnly.out" />
            <param name="Append" value="true" />
            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="%m%n" />
            </layout>
    </appender>

and let the subclass accept the File parameter, derive the LOG_ROOT path, and append it to the file name before calling super class methods.

I hope that helps in some way,

-gMale

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