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.
Deprecated feature: The JRas framework that is described in this documentation is deprecated. However, we can achieve the same results with Java logging.depfeat
Designers and developers of applications that run with or under WAS, such as servlets, JSP 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 your code:
- Your messages are displayed in the WAS standard log files, in a standard message format with more data, such as a date and time stamp that are added automatically.
- We can more easily correlate problems and events in our own application to problems and events associated with WAS components.
- Use the WAS log file management features.
- We can view your messages with the Log and Trace Analyzer tool.
Tasks
- Configure any of the supported types of logging as needed. Using one of the following methods:
- Configure Java logging with the administrative console.
- Enable access logging with the administrative console.
- Configure applications to use Jakarta Commons Logging.
- Customize the properties to meet your 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.
Use the WebSphere log and trace infrastructure for all of our log content to make problem source identification simpler.bprac
- Restart the application server after we change the static configuration.
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 The following example security policy grants permission to modify logging properties:
////////////////////////////////////////////////// // // WAS 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
- Enable access logging
- Configure applications to use Jakarta Commons Logging
- Programming with the JRas framework
- Logging messages and trace data for Java server applications
- Logging Common Base Events in WAS
Configure Java logging with the administrative console