How do I configure logging?

Glassfish use the Java java.util.logging system as the foundation for all of its logging. Consult the proper JDK documentation for more information on java.util.logging.

The primary interface for configuring Glassfish logging is the Application Server -> Logging tab in the admin console.

The Logging tab itself contains two tabs: General and Log Levels.

The General tab is use to configure what files the logs are written to, whether to use Syslog, etc.

The most common attributes you may wish to customize on the General tab are the Log File,
File Rotation Limit, or File Rotation Time Limit.

The Log File property tells the server what file name should be used for the system log file.

File Rotation Limit tells the server how large a file may get before the current log file is renamed and a new log file is create. The unit is number of bytes, so 2000000 would be a 2MB file.

File Rotation Time Limit tells the server how long a file can be around before it a new file is created. The unit is the number of minutes, so 60 would create a new log file every hour. Note, that the Time Limit will rotate a file regardless of the file size.

The Log Levels tab is used to change the levels of logging within the server.

While common practice within the development community names their loggers after the class name the logger is used in, the Glassfish developers instead consolidated the loggers in to subsystems. For example, the Web Container category covers all of the classes within the embedded Tomcat container and JSP compiler, as well as the other internal web container classes.

Use the drop down lists to select the appropriate level of logging for each subsystem. The default is INFO. FINEST is the highest leve of logging, SEVERE is the most coarse, and OFF turns logging off completely for that subsystem.

These changes will take effect immediately and can be used in a running container to change levels on the fly.

Of special note here is the Properties section at the bottom of the page.

These can be used to fine tune logging and, especially, change the logging levels of your own classes.

If you use the java.util.logging system in your own application, then you can add properties here to affect your loggers directly.

Assume that all of your classes are rooted in the com.example domain, and assume that you name all of your Loggers after the class name.

Adding a property with name: com.example value: INFO would set all of your Loggers at the INFO level.

Now say you were having an issue on a server with a Servlet, perhaps com.example.mywebapp.BuggyServlet.

On the running server, you can simply add a new property with name: com.example.mywebapp.BuggyServlet value: FINE, and any new log messages within BuggyServlet would now be forwarded to the log. When you're done gathering your now more detailed information, simply come back and either delete the property, or change it to a higher logging level (such as INFO). This can be a great boon on a production server, and you don't have to create a custom interface to leverage this functionality.