Configure JDK Logging in JBoss AS 7

I personally prefer logging using JDK logging API (java.util.logging package). It’s darn easy to use and comes with the JDK. IBM’s WebSphere was the first app server to switch to JDK logging. Now, JBoss 7 is also integrated with it. When developing, I need to bump up the log level to FINE. In this article, I will explain how to do that.

A typical class doing logging will look like this.


public class TestBean {
    Logger logger = Logger.getLogger(getClass().getName());
    public void someMethod() {
        logger.fine("someMethod() called");

Note, we use the class name as the log category name. This is the best practice. This helps us configure log level for the whole package.

In JBoss 7, logging is configured using the domain file (standalone.xml or domain.xml). During development using Eclipse JBoss Tools, we use the standalone profile. So, open the file <JBOSS>/standalone/configuration/standalone.xml. Locate the logging subsystem. It starts from this line:

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

Configure the log level for your Java package by adding these lines to the subsystem. This will set the log level to FINE.

<logger category="">
 <level name="FINE"/>

You will also need to increase the log level for the console handler. Only then the low priority messages will show up in Eclipse Console view. Change the log level as shown below.

<console-handler name="CONSOLE">
 <level name="FINE"/>
   <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

Save and close the file. Restart the server for the changes to take effect. That’s it. Now, low priority log messages from your code will start to show up in the console.

2 thoughts on “Configure JDK Logging in JBoss AS 7

  1. Just to add to this you can execute a CLI command or use the web console to add loggers and change levels at runtime.

    The CLI commands for the above two operations are:
    /subsystem=logging/console-handler=CONSOLE:write-attribute(name=level, value=FINE)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s