Sun GlassFish Enterprise Server v3 Prelude Administration Guide

Configuring Logging

This section explains how to configure logging for Enterprise Server by setting properties in the logging.properties file. Log level configuration changes are dynamic and do not require that you restart the server, but other configuration changes do require you to restart the server.

The following topics are addressed here:

Configuring Log Handler Elements

The following tasks apply to configuring log handler elements:

ProcedureTo Set Handler-Specific Properties

You can modify logging behavior by setting properties in the logging.properties file as follows:

  1. In a text editor, find the property that you want to modify and make your changes.

    The following properties are available:

    File Description

    Contains the name and location of the log file. By default, the name is server.log and the location is the logs directory. These can be changed.

    com.sun.enterprise.server.logging.FileandSyslogHandler.file=logs/server.log
    File Rotation Time Limit

    Rotates the log file based on time in minutes. If defined, time limit takes precedence over size limit. If set to 0 (the default), there is no rotation based on time.

    com.sun.enterprise.server.logging.FileandSyslogHandler.rotationTimelimitInMinutes=0
    File Rotation Size Limit

    Rotates the log file based on limit in bytes. If set to 0 (the default), there is no rotation based on file size. 500000 is the minimum.

    com.sun.enterprise.server.logging.FileandSyslogHandler.rotationLimitInBytes=0
    Formatter

    Uses UniformLogFormatter to format the records in the log file.

    com.sun.enterprise.server.logging.FileandSyslogHandler.formatter=com.
    sun.enterprise.server.logging.UniformLogFormatter
  2. Save the file.

  3. To apply your changes, restart Enterprise Server.

    1. Stop Enterprise Server.

      For instructions, see To Stop a Domain (or Server).

    2. Start Enterprise Server.

      For instructions, see To Start a Domain (or Server).


Example 9–1 Changing a Handler-Specific Logging Property

The following example changes the rotationTimelimitInMinutes from 0 (the default) to 90 minutes:

Before:


com.sun.enterprise.server.logging.FileandSyslogHandler.rotationTimelimitInMinutes=0

After: :


com.sun.enterprise.server.logging.FileandSyslogHandler.rotationTimelimitInMinutes=90

ProcedureTo Add a Log Handler

A comma-separated list of log handlers is installed during startup of the JavaTM Virtual Machine (JVMTM) host. The default log handler that is provided in the logging. properties file, ConsoleHandler, is configured as follows:


handlers= java.util.logging.ConsoleHandler

In Enterprise Server, the best approach to developing a handler is to define a Hundred-Kilobyte Kernel (HK2) component which implements the handler contract. Enterprise Server registers this handler automatically because it is an HK2 component, and there is no task required of the administrator.

To implement a new handler that is not developed as an HK2 component, you need to add the new handler to the logging.properties file after the developer has put the new handler JAR file into the /lib directory.

  1. In a text editor, add the new file handler to the line that begins with handlers=.

  2. Save the file.

  3. To apply your changes, restart Enterprise Server.

    1. Stop Enterprise Server.

      For instructions, see To Stop a Domain (or Server).

    2. Start Enterprise Server.

      For instructions, see To Start a Domain (or Server).


Example 9–2 Adding a New Log Handler

The following example adds the new logger com.example.logging.MyHandler:

Before:


handlers= java.util.logging.ConsoleHandler

After:


handlers= java.util.logging.ConsoleHandler, com.example.logging.MyHandler

Setting Log Levels

The log level describes the type of material that is contained in the message. The following values apply: SEVERE, WARNING, INFO, CONFIG, FINE, FINER, and FINEST. These log levels are hierarchically inclusive, which means that if you set a particular log level, such as INFO, the messages that have log levels above that level (SEVERE and WARNING) are also included. If you set the log level to the lowest level, FINEST, your output will include all the messages in the file. The default setting is INFO.

There are two levels of log settings available: global and logger-specific. If you have chosen a logger-specific setting that is different from the global setting, the logger-specific setting takes precedence.

Because setting log levels is a dynamic operation, you do not need to restart Enterprise Server for changes to take effect.

The following topics are addressed here:

ProcedureTo Set the Global Log Level

The global log level specifies which kinds of events are logged across all loggers. The default level for message output to the console is INFO (which also includes SEVERE and WARNING messages).

The ConsoleHandler has a separate log level setting that limits the messages that are displayed. For example:


java.util.logging.ConsoleHandler.level = INFO 
java.util.logging.ConsoleHandler.formatter = 
com.sun.enterprise.server.logging.UniformLogFormatter
  1. In a text editor, find the ConsoleHandler log level line and make your changes.

  2. Save the file.


Example 9–3 Changing the Global Log Level for All Loggers

If you set the log level at the root level, you are setting the level of all loggers. The following example sets the log level for all loggers to INFO:

.level= INFO

ProcedureTo Set Logger-Specific Properties

Logger-specific properties provide extra control for the logger of each module. By default, these properties are set to log level FINE in the logging. properties file, however, the lines in the file are commented out. The lines for the loggers might look like this (the modules are indicated in bold):


#javax.enterprise.system.tools.level=FINE
#javax.enterprise.system.container.ejb.level=FINE
#javax.enterprise.system.core.security.level=FINE
#javax.enterprise.system.tools.admin.level=FINE
#javax.enterprise.level=FINE
#javax.enterprise.system.container.web.level=FINE

For any given module logger, such as the EJB logger, the global log level can be overridden by the module-specific setting.

  1. In a text editor, uncomment the line that applies to the logger that you want to modify.

    Remove the #. The logger is activated using the default level INFO.

  2. Set the property to the desired log level.

    Your choices are SEVERE, WARNING, INFO, CONFIG, FINE, FINER, and FINEST.

  3. Save the file.

    The log levels are automatically updated.


Example 9–4 Changing the Log Level for the Console Handler

The following example changes the log level for ConsoleHandler from INFO to FINE

Before:


java.util.logging.ConsoleHandler.level = INFO

After:


java.util.logging.ConsoleHandler.level = FINE


Example 9–5 Setting a Log Level for a Specific Logger

The following example sets the log level for the EJB logger to SEVERE (overriding the global level INFO)

Before:

#javax.enterprise.system.container.ejb.level=FINE

After: :

javax.enterprise.system.container.ejb.level=SEVERE

ProcedureTo Change the Log File Name or Directory

By default, the name of the log output file is server.log and it is located in domain-dir/logs. You can change the name or location of the file by editing the logging.properties file as follows:

  1. In a text editor, find the following line:

    com.sun.enterprise.server.logging.FileandSyslogHandler.file=logs/server.log

    In this line, logs indicates the directory where the file is located, and server.log is the file name.

  2. Make your changes and save the file.

  3. To apply your changes, restart Enterprise Server.

    1. Stop Enterprise Server.

      For instructions, see To Stop a Domain (or Server).

    2. Start Enterprise Server.

      For instructions, see To Start a Domain (or Server).


Example 9–6 Changing the Name and Location of the Log File

The following example changes the log file name from server.log to myLogging.log and changes the location from the logs directory to the dpin directory:

Before:

com.sun.enterprise.server.logging.FileandSyslogHandler.file=logs/server.log

After:

com.sun.enterprise.server.logging.FileandSyslogHandler.file=dpin/myLogging.log