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.