2 Replies Latest reply on Dec 17, 2013 2:38 AM by wdfink

    ConsoleHandler: Redirect to STDERR

    bechtleag

      Hello,

       

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

       

      log4j.rootLogger=DEBUG, bridge

      log4j.appender.bridge=com.redhat.gss.log4j.JULAppender

       

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

       

      <root-logger>

          <level name="DEBUG"/>

          <handlers>

              <handler name="CONSOLE"/>

          </handlers>

      </root-logger>

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

          <level name="DEBUG"/>

          <formatter>

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

          </formatter>

      </console-handler>

       

      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:

       

      log4j.appender.stderr=org.apache.log4j.ConsoleAppender

      log4j.appender.stderr.Target=System.err

      log4j.appender.stderr.Threshold=ERROR


      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.

       

      Regards,

      C. Klein (Bechtle AG)

        • 1. Re: ConsoleHandler: Redirect to STDERR
          jamezp

          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)
          
          /subsystem=logging/console-handler=CONSOLE:write-attribute(name=level,value=WARN)
          
          /subsystem=logging/root-logger=ROOT:add-handler(name=stderr)
          

           

           

          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
            wdfink

            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.