| Sun Java System Application Server |
The Logging application demonstrates using Logger objects
to log messages for a specific system or application component.
Log messages can help developers to debug their applications.
The Java Standard Edition (J2SE) a package java.util.logging contains all the classes and interfaces for the core logging facilities.
Typically, a developer uses a Logger object with a name that corresponds
to the class or package name of the application to generate log messages at
any of seven severity levels (defined by the Level class). These
log messages might report errors, warnings, or informational messages. They
can include debugging information, or even trace the execution of important
methods within the program.
The messages are generated and logged according to a default logging configuration file which specifies where the messages are directed (to the console, a file, a network socket, or a combination of these outputs), how they are formatted (as ASCII text or XML documents), and at what severity level they are logged (messages with a severity below the specified level are discarded and should not significantly affect performance). The system administrator or end user of the application can modify this default configuration as needed.
Applications can use the java.util.logging package in various ways. The general procedure is:
Logger object by calling the
static Logger.getLogger() method, passing
the class or package name of the application as the logger name.
Logger instance methods to generate log messages. The
most straightforward methods have names that correspond to severity levels,
such as severe(), warning(), info(),
and debug().
This sample demonstrates using java.util.logging.Logger to print
the INFO log and the FINE log.
The sample code includes a range of logging APIs. Based on user selection,
the application starts logging messages to the server.log file.
However, messages at the FINE selection require additional steps. See Run the Application for details.
The following steps describe the execution of this sample:
The general instructions for building, deploying, and running sample applications are provided in Building, Deploying, and Running Sample Applications. In reading this document, use the following application-specific variables for this application:
install_dir is the directory where Application Server
is installed.
app_dir is the application base directory: install_dir/samples/logging/apps/simple.
logging-helloworld.ear.
Follow this general procedure:
build.xml, is in the app_dir
directory, specifically, install_dir/samples/logging/apps/simple.
install_dir/samples/logging/apps/simple/logging-helloworld.ear.
Run the application by entering this URL in your browser:
http://hostname:port/logging-helloworld
As described above, the application includes options for two log levels, INFO
and FINE. While most Log messages are stored in the server.log
file, FINE messages are filtered out.
To view messages that are logged at the FINE level, you'll need to set the
log level for samples.logging.simple.servlet to FINE from the Admin
Console. Follow the steps below:
http://localhost:admin.port/asadmin
samples.logging.simple.servlet in the Name field, and
type FINE in the Value field.samples.logging.simple.servlet
in the Custom Logger text field, then cllicking the Search button at the bottom
of the Log Viewer window.Copyright © 2006 Sun Microsystems, Inc. All rights reserved.