Configuring a JBoss Handler which writes in a distinct file logs for a package

This article shows how to configure a JBoss Logging Handler for a specific package (category) to be written in a separate log file.

Sometimes you need to add verbosity to a specific JBoss/WildFly package but you don’t want to mix it with the application server’s logs. So, in order to do that, you need to perform the following steps:

  • Define a Handler which points to a file path. In most cases, the Periodic Rotating File Handler is the best choice
  • Define a Logger, which contains the package (“category”) to be traced and the level of verbosity
<periodic-rotating-file-handler name="JTA-LOG" autoflush="true">
            <file relative-to="jboss.server.log.dir" path="${jboss.node.name}_jta.log"/>
            <rotate-size value="20000"/>
            <max-backup-index value="3"/>
            <suffix value=".yyyy-MM-dd"/>
            <suffix value=".yyyy-MM-dd"/>
            <append value="true"/>
</periodic-rotating-file-handler>
 
<logger category="com.arjuna.ats.jta" use-parent-handlers="false">
        <level name="TRACE"/>
        <handlers>
                <handler name="JTA-LOG"/>
        </handlers>
</logger>

<root-logger>
        <level name="INFO"/>
        <handlers>
            <handler name="JTA-LOG"/>
            <handler name="CONSOLE"/>
            <handler name="FILE"/>           
        </handlers>
</root-logger>

In this example configuration, we have defined a Perodic Rotating File Handler writing a file named ${jboss.node.name}_jta.log in the standard log dir. This Handler traces the package “com.arjuna.ats.jta” and it is added to the roo-logger. This will help you to keep the logs for a specific package in a separate log file.


Recommended Articles

Configure WildFly's Periodic File Handler with Advanced Settings and Rotations

Learn how to configure the Periodic File Handler in WildFly for efficient log management. #WildFly #JavaLogging #CloudNative

How to Compress Logs in WildFly (Native Handler and Log4j2)

How to compress logs in WildFly using the native Periodic Rotating File Handler, and with Log4j2 (2.26.0). Covers deprecated Log4j 1.x syntax, production log rotation strategies, and container/Kubernetes logging best practices.

Inspection and Management of WildFly Logs via Command Line Interface - A Comprehensive Guide

Learn how to inspect WildFly logs using CLI with detailed examples and parameters for efficient log management.

How to Change WildFly Log Levels Using Management Instruments - A Comprehensive Guide

Learn two simple ways to change log levels in WildFly with management instruments. Explore the pros and cons of changing the Root Logger settings vs. modifying specific Logger verbosity.