2 Replies Latest reply on Dec 17, 2013 2:38 AM by Wolf-Dieter Fink

    ConsoleHandler: Redirect to STDERR

    Bechtle AG Newbie



      I have a log4j.properties with a JULAppender...


      log4j.rootLogger=DEBUG, bridge



      ... which redirect anything to the ConsoleHandler defined in my standalone-full.xml ...



          <level name="DEBUG"/>


              <handler name="CONSOLE"/>



      <console-handler name="CONSOLE" autoflush="true">

          <level name="DEBUG"/>


              <pattern-formatter pattern="%K{level}%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>




      We invoke JBOSS with the "standalone.sh"-Skript and redirect the output to seperate logfiles "jboss.log" and "jboss.err" dependent on the output channel STDOUT and STDERR:


      bin/standalone.sh -server-config=standalone-full.xml > >(tee jboss.log) 2> >(tee jboss.err >&2)

      But it seems like everything is collected on STDOUT by JBOSS. At least we do not get any output within the "jboss.err" file. Using a log4j.properties solely one could use something like that:





      So I think there must be some possibility to define the target with JBOSS 7 too but we didn't get it so far.


      Any help is appreciated.



      C. Klein (Bechtle AG)

        • 1. Re: ConsoleHandler: Redirect to STDERR
          James Perkins Master

          By default the console-handler writes to "System.out" (stdout). The console-handler will not write to multiple streams. You can define an additional console-handler with a level of ERROR to write to "System.err" though. Then change the level on the default CONSOLE to WARN and add the new stderr handler to the root-logger.


          The CLI do do this would be something like.

          /subsystem=logging/console-handler=stderr:add(autoflush=true,level=ERROR,formatter="%K{level}%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n", target=System.err)



          Note depending on the version of JBoss AS/EAP/WildFly you're using the last operation might need to be root-logger-assign-handler(name=stderr).



          James R. Perkins

          • 2. Re: ConsoleHandler: Redirect to STDERR
            Wolf-Dieter Fink Master

            Additional to I would avoid such redirecting in production as you might have several drawbacks in performance and handling.

            If you need a separate file with the ERROR/WARN messages I would add a file appender with the jboss.err file and restrict the level to that.