How can I configure two differently formatted Console Handlers?

时间:2018-09-22 22:52:50

标签: logging java-ee wildfly

Is it possible to:

--- Let the wildfly server’s logger use the Console-Handler “CONSOLE” (configured below) to write to the wildfly console using a format defined by the “COLOR PATTERN” format.

--- Add Loggers to my server side java classes that use the Console-Handler “MY-CONSOLE” (configured below) to write to the wildfly console. using a format defined by MY-PATTERN”?

Here is the logging subsystem definition from my wildfly 10 standalone-full.xml configuration file. (MY-PATTERN is a silly test format makes it obvious when I have succeeded in getting it used. I'll replace it with a serious pattern if this can work. )

<subsystem xmlns="urn:jboss:domain:logging:3.0">

  <console-handler name="CONSOLE">
    <level name="INFO"/>
    <formatter>
      <named-formatter name="COLOR-PATTERN"/>
    </formatter>
  </console-handler>

  <console-handler name="MY-CONSOLE" autoflush="true">
    <formatter>
      <named-formatter name="MY-PATTERN"/>
    </formatter>
    <target name="System.out"/>
  </console-handler>

  <console-handler name="GOTEST-HANDLER">
    <level name="INFO"/>
    <formatter>
      <named-formatter name="GOTEST-PATTERN"/>
    </formatter>
  </console-handler>

  <periodic-rotating-file-handler name="FILE" autoflush="true">
    <formatter>
      <named-formatter name="PATTERN"/>
    </formatter>
    <file relative-to="jboss.server.log.dir" path="server.log"/>
      <suffix value=".yyyy-MM-dd"/>
      <append value="true"/>
  </periodic-rotating-file-handler>
  <logger category="org.america3.gotest" use-parent-handlers="false">
    <level name="ALL"/>
    <handlers>
      <handler name="GOTEST-HANDLER"/>
    </handlers>
  </logger>
  <logger category="com.arjuna">
    <level name="WARN"/>
  </logger>
  <logger category="org.jboss.as.config">
    <level name="DEBUG"/>
  </logger>
  <logger category="sun.rmi">
    <level name="WARN"/>
  </logger>
  <root-logger>
    <level name="INFO"/>
    <handlers>
      <handler name="CONSOLE"/>
      <handler name="FILE"/>
    </handlers>
  </root-logger>
  <formatter name="PATTERN">
    <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
  </formatter>
  <formatter name="COLOR-PATTERN">
    <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
  </formatter>
  <formatter name="MY-PATTERN">
    <pattern-formatter pattern="MeMeMe%s%n"/>
  </formatter>
  <formatter name="GOTEST-PATTERN">
    <pattern-formatter pattern="%s%n"/>
  </formatter>
</subsystem>

0 个答案:

没有答案