This chapter provides instructions on how to configure logging and how to view log information in the Sun GlassFishTM Enterprise Server v3 Prelude environment.
The following topics are addressed here:
Logging is the process by which Enterprise Server captures data about events that occur during Enterprise Server operation. This data is recorded in a log file and is usually the first source of information when Enterprise Server problems occur.
Although application components can use the Apache Commons Logging Library to record messages, the platform standard JSR 047 API is recommended for better log configuration.
The following topics are addressed here:
Enterprise Server log records are captured in the server.log file, typically located in domain-dir/logs. You can change the default name or location of the log file by following instructions in To Change the Log File Name or Directory.
Enterprise Server log records follow a uniform format:
|
[#|yyyy-mm-ddThh:mm:ss.SSS-Z|Log Level|ProductName-Version|LoggerName|Key Value Pairs|Message|#] |
[# and #] mark the beginning and end of the record.
The vertical bar (|) separates the fields of the record.
yyyy-mm-ddThh:mm:ss.SSSS-Z specifies the date and time that the record was created. For example: 2006-10-21T13:25:53.852-0400
Log Level specifies the desired log level. You can select any of the following values: SEVERE, WARNING, INFO, CONFIG, FINE, FINER, and FINEST. The default is INFO.
ProductName-Version refers to the current version of the Enterprise Server. For example: glassfish
LoggerName is a hierarchical logger namespace that identifies the source of the log module. For example: javax.enterprise.system.core
Key Value Pairs refers to pairs of key names and values, typically a thread ID. For example: _ThreadID=14;
Message is the text of the log message. For all Enterprise Server SEVERE and WARNING messages and for many INFO messages, the message begins with a message ID that consists of a module code and a numerical value. For example: CORE5004
An example log record might look like this:
[#|2006-10-21T13:25:53.852-0400|INFO|GlassFish10.0|javax.enterprise. system.core|_ThreadID=13;|CORE5004: Resource Deployed: [cr:jms/DurableConnectionFactory].|#]
You can configure logging by editing the logging.properties file. The default logging.properties file is located in the same directory as the domain.xml file, typically domain-dir/config. You can choose a different file name by using the java.util.logging.config.file system property to specify a file name. For example:
java -Djava.util.logging.config.file=myfile |
A logger is provided for each Enterprise Server module. The following table lists the names of the modules and the namespace for each logger.
Table 9–1 Logger Namespaces for Enterprise Server Modules
Module Name |
Namespace |
---|---|
Admin |
javax.enterprise.system.tools.admin |
Classloader |
javax.enterprise.system.core.classloading |
Configuration |
javax.enterprise.system.core.config |
Deployment |
javax.enterprise.system.tools.deployment |
Persistence |
oracle.toplink.essentials, javax.enterprise.resource.jdo, javax.enterprise.system.container.cmp |
Root |
javax.enterprise |
Security |
javax.enterprise.system.core.security |
Util |
javax.enterprise.system.util |
Verifier |
javax.enterprise.system.tools.verifier |
Web container |
javax.enterprise.system.container.web org.apache.catalina org.apache.coyote org.apache.jasper |
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:
The following tasks apply to configuring log handler elements:
You can modify logging behavior by setting properties in the logging.properties file as follows:
In a text editor, find the property that you want to modify and make your changes.
The following properties are available:
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
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
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
Uses UniformLogFormatter to format the records in the log file.
com.sun.enterprise.server.logging.FileandSyslogHandler.formatter=com. sun.enterprise.server.logging.UniformLogFormatter
Save the file.
To apply your changes, restart Enterprise Server.
Stop Enterprise Server.
For instructions, see To Stop a Domain (or Server).
Start Enterprise Server.
For instructions, see To Start a Domain (or Server).
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 |
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.
In a text editor, add the new file handler to the line that begins with handlers=.
Save the file.
To apply your changes, restart Enterprise Server.
Stop Enterprise Server.
For instructions, see To Stop a Domain (or Server).
Start Enterprise Server.
For instructions, see To Start a Domain (or Server).
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 |
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:
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 |
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
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.
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.
Set the property to the desired log level.
Your choices are SEVERE, WARNING, INFO, CONFIG, FINE, FINER, and FINEST.
Save the file.
The log levels are automatically updated.
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 |
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
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:
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.
Make your changes and save the file.
To apply your changes, restart Enterprise Server.
Stop Enterprise Server.
For instructions, see To Stop a Domain (or Server).
Start Enterprise Server.
For instructions, see To Start a Domain (or Server).
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
By default, all log information is captured in the server.log file, typically located in domain-dir/logs. To view information that has been collected for a module, you can open the server.log file in a text editor and search for the module that you are interested in.
You can also use the command-line file viewing commands, such as tail, grep, or more.