1 Reply Latest reply on Apr 4, 2016 5:42 PM by James Perkins

    Can I use Java Logger to remove the 1/2 page of patterned info that is now added?

    George Berish Novice

      I would like to use Java's Logger in my MessageDrivenBean and SessionBeans to write to WildFly's console and log file in my own format.

       

      I tried adding this to standalone.xml

       

      <console-handler name="MY-CONSOLE-HANDLER">

         <level name="INFO"/>

         <formatter>

           <named-formatter name="MY-PATTERN"/>

         </formatter>

      </console-handler>

       

      <logger category="MY-LOGGER" use-parent-handlers="false">

            <level name="DEBUG"/>

      <handlers>

                <handler name="MY-CONSOLE-HANDLER"/>

      </handlers>

          </logger>

      <console-handler name="MY-CONSOLE-HANDLER">

              <level name="INFO"/>

      <formatter>

      <named-formatter name="MY-PATTERN"/>

      </formatter>

      </console-handler>

              <formatter name="MY-PATTERN">

      <pattern-formatter pattern="%n"/>

      </formatter>

       

      And this in my MessageDrivenBean:

       

      private static Logger  logger  = Logger.getLogger("MY-LOGGGER");

        @PostConstruct

        public void myInit () {

          System.out.println("logger.info(\"My Test Message 1\")" );

          logger.info("My Test Message 1");

        }

      --------- I GET THIS --------

          ...

          17:29:22,600 INFO INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final) started in 6834ms - Started 602 of 788 services (264 services are lazy, passive or on-demand)

          ...

          17:30:04,324 INFO  [stdout] (Thread-1 (HornetQ-client-global-threads-463164371)) About to try: logger.info("My Test Message 1")

          17:30:04,324 INFO  [MY-LOGGGER] (Thread-1 (HornetQ-client-global-threads-463164371)) My Test Message 1

          ...

      --------- BUT I WANT THIS --------

          ...

          17:29:22,600 INFO INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final) started in 6834ms - Started 602 of 788 services (264 services are lazy, passive or on-demand)

          ...

          About to try:   logger.info("My Test Message 1")

          My Test Message 1

          ...

      -----------------------------------

       

      So I guess the very first question is this:   Is that possible for me to  write the to the log an console without all the Pattern'd info to take up half the page, and without messing up the Pattern'd info Wildfly puts in front of lines it writes ?

       

      If so, can anyone point me in the right direction to get that done?  I obviously don't have a grasp of Java Logger's approach, and can't find a simple example yet as a starting point for that knowledge tree. I really need a simple thing that works as an anchore.

       

      Note: Just for info: I played with instantiating my own Handler and Formatter classes.  And then taking the MY-LOGGER get and replacing its handlers with mine with this code:

      private static Logger  logger  = Logger.getLogger("MY-LOGGGER");

      @PostConstruct

      public void myInit () {

        Handler[] handlers = logger.getHandlers();

        for (Handler handler : handlers) {

          logger.removeHandler(handler);

        }

        logger.addHandler(GO_TEST_HANDLER);

        System.out.println("logger.info(\"My Test Message 1\")" );

        logger.info("My Test Message 1");

      }

       

      And that went no where (but here are the classes anyway)

       

      public class GoTestHandler extends StreamHandler {

        public GoTestHandler() {

          super();

          this.setFormatter(new GoTestFormatter());

        }

      }

      .

      public class GoTestFormatter extends Formatter {

         @Override

        public String format(LogRecord record) {

          StringBuffer sb = new StringBuffer();

          sb.append("XXX   "); // the XXX is just to see if this method ever got used

          sb.append(this.formatMessage (record));

          System.out.println("From GoTestFormater.format()");

          return sb.toString();

        }

      }

       

      Any help?