WebSphere stdout/stderr logging redirect

Working on an application using log4j and deployed in WebSphere, we had the need to output the logs on the SystemOut.log and SystemErr.log files. In WebSphere with the normal configuration it outputs all the logs in the SystemOut.log.

We wanted only the ERROR and WARN level logs redirected to the SystemErr.log file, so we used the configuration below for the log appenders.

log4j.properties


########################################
# LOG4J-properties
########################################

# This is the configuring for logging displayed in the Application Server
log4j.rootCategory=DEBUG, stdout, stderr

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=DEBUG
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%-5p] %t (%d{dd/MM/yy HH:mm:ss}) %c{1} - %m\n
log4j.appender.stdout.filter.filter1=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.stdout.filter.filter1.levelMin=DEBUG
log4j.appender.stdout.filter.filter1.levelMax=INFO

log4j.appender.stderr=org.apache.log4j.ConsoleAppender
log4j.appender.stderr.Threshold=WARN
log4j.appender.stderr.Target=System.err
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
log4j.appender.stderr.layout.ConversionPattern=[%-5p] %t (%d{dd/MM/yy HH:mm:ss}) %c{1} - %m\n

log4j.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
        <param name="threshold" value="debug" />
        <param name="target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%-5p] %t (%d{dd/MM/yy HH:mm:ss}) %{1} - %m\n" />
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="debug" />
            <param name="LevelMax" value="info" />
        </filter>
    </appender>
    <appender name="stderr" class="org.apache.log4j.ConsoleAppender">
        <param name="threshold" value="warn" />
        <param name="target" value="System.err"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%-5p] %t (%d{dd/MM/yy HH:mm:ss}) %c{1} - %m\n" />
        </layout>
    </appender>
    <root>
        <level value="DEBUG"/>
        <appender-ref ref="stdout"/>
        <appender-ref ref="stderr"/>
    </root>
</log4j:configuration>

Comments

Popular posts from this blog

JSF2 View Scope with Spring Core

Spring Data Repositories: Query by Specification