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?
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
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
精彩评论