Add logging and tracing to the application
We can add logging and tracing to applications to help analyze performance and diagnose problems in WebSphere Application Server.
Deprecation: The JRas framework described in this information center is deprecated. However, we can achieve the same results using Java logging.Designers and developers of applications that run with or under WebSphere Application Server, such as servlets, JSPs files, enterprise beans, client applications, and their supporting classes, might find it useful to use Java logging for generating their application logging.
This approach has advantages over adding System.out.println statements to the code:
- Your messages are displayed in the WAS standard log files, using a standard message format with additional data, such as a date and time stamp added automatically.
- We can more easily correlate problems and events in our own application to problems and events associated with WebSphere Application Server components.
- We can take advantage of the WAS log file management features.
- (dist) We can view the messages with the Log and Trace Analyzer tool.
- Enable and configure any of the supported types of logging as needed. Use one of the following methods:
- Configure Java logging using the administrative console
- Configure applications to use Jakarta Commons Logging
- Customize the properties to meet the logging needs. For example, enable or disable a particular log, specify the number of logs to be kept, and specify a format for log output.
- If we do not want log and trace from Jakarta Commons Logging to use the WebSphere log and trace infrastructure, reconfigure the Jakarta Commons Logging.
Best practice: Use the WebSphere log and trace infrastructure for all of the log content to make problem source identification simpler.bprac
- Restart the application server after making static configuration changes.
Example
The sample security policy that follows grants access to the file system and runtime classes. Include this security policy, with the entry permission java.util.logging.LoggingPermission "control", in the META-INF directory of the application if we want the applications to programmatically alter controlled properties of loggers and handlers. The META-INF file is located in the following locations for the different module types:
Project name Location EJB projects ejbModule/META-INF/MANIFEST.MF Application client projects appClientModule/META-INF/MANIFEST.MF Dynamic web projects WebContent/META-INF/MANIFEST.MF Connector projects connectorModule/META-INF/MANIFEST.MF Below is a sample security policy that grants permission to modify logging properties:
////////////////////////////////////////////////// // // WebSphere Application Server Security Policy // ////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // Allow all access to the file system and runtime classes //////////////////////////////////////////////////////////////////////// grant codeBase "file:${application}" { permission java.util.logging.LoggingPermission "control"; };
Subtopics
- Use Java logging in an application
This topic describes how to use Java logging within an application.
- Configure applications to use Jakarta Commons Logging
Jakarta Commons Logging provides a simple logging interface and thin wrappers for several logging systems. WebSphere Application Server supports Jakarta Commons Logging by providing a logger. The support does not change interfaces defined by Jakarta Commons Logging.
- Programming with the JRas framework
Use the JRas extensions to incorporate message logging and diagnostic trace into WebSphere Application Server applications.
- (zos) Logging messages and trace data for Java server applications
By using the WAS for z/OS support for logging application messages and trace data, we can improve the reliability, availability, and serviceability of any Java application that runs in a WAS for z/OS server.
- Logging Common Base Events in WebSphere Application Server
WAS uses Common Base Events within its basic logging framework. Common Base Events can be created explicitly and then logged through the Java logging API, or can be created implicitly using the Java logging API directly.
Related tasks
Configure Java logging using the administrative console