Skip to main content

Changing Log Levels in Embedded GlassFish

Posted by bhavanishankar on December 14, 2010 at 11:59 PM PST

This blog shows how to programatically change the log levels of a particular logger in Embedded GlassFish.

I did a search on the internet for information on how to change the log levels of a particular logger in Embedded GlassFish. The only information I could find was which requires changing $JAVA_HOME/jre/lib/ But I am not comfortable changing it at the JDK level.

So, I wrote the following piece of code. May be the Embedded GlassFish users will find it useful:

import org.glassfish.embeddable.*;

// Create Embedded GlassFish
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish();

// Set the log levels. For example, set 'deployment' and 'server' log levels to FINEST

// Start Embedded GlassFish and deploy an application.
// You will see all the FINEST logs printed on the console.
new File("sample.war"));

// Dispose Embedded GlassFish


The above code uses GlassFish 3.1 Embedded APIs and should be run using latest Embedded GlassFish JAR (3.1-SNAPSHOT is here).

Another alternative non programmatic way is to create a custom logging configuration file ( with the following contents:

handlers= java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = FINEST = FINEST
javax.enterprise.system.level = FINEST

and pass it while invoking your application (say MyEmbeddedGlassFish), like this:

java MyEmbeddedGlassFish

(Refer for the logger names)

Related Topics >>