GlassFish V3 logging changes
Logging in GlassFish V3 has undergone some changes to leverage the logging utility in JDK. This blogs reviews where we are with the logging mechanism in GlassFish Prelude and since not all of the features are implemented in the Prelude release yet, I'll go over how to make use of the functionality that is there.
The most significant change is that for now we don't have support in the Admin GUI or the command line tool asadmin. That support will be provided in the final release of GlassFish V3. For now, developers using Prelude will have to edit the logging.properties file found in the domain config directory where you find the domain.xml file. Let's take a look at what can be done.
Developers can update the logger level, change the log filename and set rotation of log files based on file size or a time limit. Some of these changes require a restart of the server and some don't.
First let's talk about setting log levels on loggers. Changes to logger levels are dynamic and don't require a server restart. At the end of the logging.properties file you will find a list of loggers in GlassFish. I have included the most common loggers so developers can easily find what they want. Below is an excerpt from that file.
# EJB Logger
By default all the logger levels are set to INFO because the root level is set to INFO. If the log level is not set on a logger then it inherits the level of its parent going up the chain until it finds a logger with the level set or it reaches the root logger. To set the level on a specific logger you simply uncomment the line in logging.properties corresponding to the logger and set the level appropriately. Upon saving the file the logging mechanism is notified of a change to the file and resets the log levels for all known loggers based on the information in the file. Note that you can create your own logger, specify the level in the logging.properties file and it will be updated too.
The log level values are SEVERE, WARNING, INFO, CONFIG, FINE, FINER, and FINEST. Each level includes messages of the level above it so if you set a logger to level INFO you will also get the SEVERE and WARNING messages in addition to the INFO.
One last note about log levels, it is valid to set the level of the loggers at any point in the logger name. For example, say you want all the loggers under javax.enterprise.system.container to print at the FINE level. You simply create a line as follows and save the file.
Once set, the logger level must be explicitly reset to change the level.
Setting file rotation is also done by changing properties in logging.properties. Changing these properties does require a server restart to take affect. There are two ways to set file rotation in Prelude. You can request files be rotated based on a file size or based on a time limit. The properties associated with file rotation are below.
# 0 for no rotation based on time
# rotation limit in bytes, 0 means no rotation, 500000 is the minimum
By default both are set to 0 or no file rotation. If both are set then rotation will be based on time. You can specify the max size of the log file reached to rotate or create the next log file or the max elapsed time reached to rotate the log file.
For now developers will need to edit the logging.properties file and it should be pretty straight forward. But remember that the team is working on providing tool support for GlassFish V3 final so it will be easier soon.