14.3.9. Configure a Custom Log Formatter in the CLI

Summary

In addition to the log formatter syntax specified in Section 14.1.15, “Log Formatter Syntax”, a custom log formatter can be created for use with any log handler. This example procedure will demonstrate this by creating a XML formatter for a console log handler.

Prerequisites

  • Access to the Management CLI for the JBoss EAP 6 server.
  • A previously configured log handler. This example procedure uses a console log handler.

Procedure 14.4. Configure a Custom XML Formatter for a Log Handler

  1. Create custom formatter.
    In this example, the following command creates a custom formatter named XML_FORMATTER that uses the java.util.logging.XMLFormatter class.
    [standalone@localhost:9999 /] /subsystem=logging/custom-formatter=XML_FORMATTER:add(class=java.util.logging.XMLFormatter, module=org.jboss.logmanager)
  2. Register a custom formatter for the log handler you want to use it with.
    In this example, the formatter from the previous step is added to a console log handler.
    [standalone@localhost:9999 /] /subsystem=logging/console-handler=HANDLER:write-attribute(name=named-formatter, value=XML_FORMATTER)
  3. Restart the JBoss EAP 6 server for the change to take effect.
    [standalone@localhost:9999 /] shutdown --restart=true
Result

The custom XML formatter is added to the console log handler. Output to the console log will be formatted in XML, for example:

<record>
  <date>2014-03-11T13:02:53</date>
  <millis>1394539373833</millis>
  <sequence>116</sequence>
  <logger>org.jboss.as</logger>
  <level>INFO</level>
  <class>org.jboss.as.server.BootstrapListener</class>
  <method>logAdminConsole</method>
  <thread>282</thread>
  <message>JBAS015951: Admin console listening on http://%s:%d</message>
  <param>127.0.0.1</param>
  <param>9990</param>
</record>