Specifying the logging file location in Websphere in a platform-independent way

17,882

Solution 1

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

Solution 2

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

Share:
17,882
Robert Munteanu
Author by

Robert Munteanu

Summary In one life, I am Robert Munteanu, software engineer for a respectable software company. I write clean Java code, I maintain application builds ... help my colleagues discover bugs with automated analysis tools. The other life is lived in open source, where I go by the developer alias "Rombert" and try go get my code in virtually every open source software I have an use for.

Updated on June 04, 2022

Comments

  • Robert Munteanu
    Robert Munteanu about 2 years

    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?