WAS v8.5 > Troubleshoot > Add logging and tracing to the applicationUse Java logging in an application
This topic describes how to use Java logging within an application. To create an application using Java logging, perform the following steps:
- Optional: Create the necessary handler, formatter, and filter classes if you need our own log files.
Use the WebSphere log and trace infrastructure to make problem source identification simpler, rather than creating separate log files.
- Optional: If localized messages are used by the application, create a resource bundle, as described in Create log resource bundles and message files.
- In the application code, get a reference to a logger instance, as described in Use a logger.
- Insert the appropriate message and trace logging statements in the application, as described in Use a logger.
Subtopics
- Use a logger
We can use Java logging to log messages and add tracing.- Java logging
Java logging is the logging toolkit provided by the java.util.logging package. Java logging provides a standard logging API for the applications.- Configure the logger hierarchy
WAS handlers are attached to the Java root logger, which is at the top of the logger hierarchy. As a result, any request from anywhere in the logger tree can be processed by WAS handlers.- Create log resource bundles and message files
We can forward messages that are written to the internal WAS logs to other processes for display. Messages that are displayed on the dmgr console, which can be running in a different location than the server process, can be localized using the late binding process. Late binding means that WAS does not localize messages when they are logged, but defers localization to the process that displays the message.- Use a logger
We can use Java logging to log messages and add tracing.- Java logging
Java logging is the logging toolkit provided by the java.util.logging package. Java logging provides a standard logging API for the applications.- Configure the logger hierarchy
WAS handlers are attached to the Java root logger, which is at the top of the logger hierarchy. As a result, any request from anywhere in the logger tree can be processed by WAS handlers.- Create log resource bundles and message files
We can forward messages that are written to the internal WAS logs to other processes for display. Messages that are displayed on the dmgr console, which can be running in a different location than the server process, can be localized using the late binding process. Late binding means that WAS does not localize messages when they are logged, but defers localization to the process that displays the message.- Logger.properties file for configuring logger settings
Use the Logger.properties file to set logger attributes for specific loggers.