How to redirect STDOUT and STDERR logging from server.log to another file in EAP 6/7?

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7

Issue

  • How can I write application messages to stdout/stderr to a separate log file rather than server.log?

Resolution

  • In standalone*.xml/domain.xml under the "logging" subsystem add the following:
            <periodic-rotating-file-handler name="CONSOLE-LOG-FILE" autoflush="true">
                <formatter>
                    <named-formatter name="PATTERN"/>
                </formatter>
                <file path="<full-path>/my_stderr_stdout.log"/>
                <suffix value=".yyyy-MM-dd"/>
                <append value="true"/>
            </periodic-rotating-file-handler>
            <logger category="stdout" use-parent-handlers="false">
                <level name="INFO"/>
                <handlers>
                    <handler name="CONSOLE-LOG-FILE"/>
                </handlers>
            </logger>
            <logger category="stderr" use-parent-handlers="false">
                <level name="ERROR"/>
                <handlers>
                    <handler name="CONSOLE-LOG-FILE"/>
                </handlers>
            </logger>
  • CLI:
/subsystem=logging/logger="stdout":add(category="stdout",handlers=["CONSOLE-LOG-FILE"],level=INFO,use-parent-handlers=false)
/subsystem=logging/logger="stderr":add(category="stderr",handlers=["CONSOLE-LOG-FILE"],level=ERROR,use-parent-handlers=false)

Root Cause

stdout and stderr messages go to the server.log file so logger categories have to be set up for each that are wired to an appropriate periodic-rotating-file-handler

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments