Logging client messages in the z/OSMF log
z/OSMF provides a client side logging framework, which you can use to log your plug-in's client messages in the z/OSMF log. Using the client side logger helps simplify debugging activities because messages for all z/OSMF plug-ins are included in the same log.
For more information about the z/OSMF log, including how to access and view the log, see the topic about working with z/OSMF runtime log files in IBM z/OS Management Facility Configuration Guide.
Setting up client side logging
To implement client side logging, add code to your plug-in that:
Sample code for setting up client side logging
Figure 2 provides sample code that you can use as a reference when setting up the client side logger.
var dojoConfig = {
isDebug: false,
parseOnLoad: false,
usePlainJson: true,
async: true,
//Specify the name and location of the client side logger package.
packages: [{name: "izuLogger", location: "/zosmf/IzuUICommon/js"}]
};
//Import the client side logger package.
require(["izuLogger/izuUILogger/log4js17"],
function(log4js){
//Create an instance of the client side logger.
var LOGGER = log4js.getLogger("com.mycompany.myproduct.mymodule.ui");
var MODULE = "MYMODULE";
var PACKAGE_NAME = "MYPACKAGE.jsp";
//Define methods for logging messages.
function init(){
var methodName="init";
var LOGPREFIX=MODULE+" "+PACKAGE_NAME+" "+methodName+": ";
LOGGER.entering(LOGPREFIX+"entry stuff");
LOGGER.finest(LOGPREFIX+"finest stuff");
LOGGER.finer(LOGPREFIX+"finer stuff");
LOGGER.info(LOGPREFIX+"info stuff");
LOGGER.warning(LOGPREFIX+"warning stuff");
LOGGER.severe(LOGPREFIX+"severe stuff");
LOGGER.exiting(LOGPREFIX+"exiting stuff");
}
});
Methods provided for the client side logger
Table 1 lists the methods you can use when setting up the client side logger, and provides summary descriptions and sample JavaScript code for each method.
Method | Description | Sample Code |
---|---|---|
log4js.getLogger(logger-ID); | Creates an instance of the client side logger for your plug-in, and assigns a unique identifier (logger-ID) to the logger. |
|
loggerName.log-level(param); | Defines the log levels (log-level) you
want the specified logger (loggerName) to include in the z/OSMF log, and takes
a single string parameter (param) that specifies the information
to log for each message. For the loggerName.severe(param) method, the client side logger automatically flushes messages to the z/OSMF log. |
|
loggerName.entering(params); | Logs the entry point of each method, and takes zero or more comma-separated parameters (params). |
|
loggerName.exiting(params); | Logs the exit point of each method, and takes zero or more comma-separated parameters (params). |
|
loggerName.logp(Level.log-level, params) | Allows you to specify the parameters (params) to include in the z/OSMF log for the specified log level (log-level). This method takes a variable number of comma-separated parameters, and is an alternative to the loggerName.log-level(param) method. |
|
loggerName.isLoggable(Level.log-level) | Verifies that the specified log level (log-level) is currently being logged. |
|
loggerName.logMessage("msgID", msgvars); | Logs the message ID as well as the values that were substituted for each parameter. The values are stored as an array. |
|
loggerName.turnOnTracing(); | Enables tracing by setting the log level to FINER. |
|
loggerName.turnOffTracing(); | Disables tracing, and sets the log level to its initial level. |
|
loggerName.turnOnPopup(); | Appends messages to a popup window. The default
log level is FINEST. You can also append messages to a popup window by setting the setpopup property to true. For more details, see Logging messages to a popup window. |
|
loggerName.turnOffPopup(); | Stops appending messages to a popup window (default), and closes the popup window. You can also stop appending messages to a popup window by setting the setpopup property to false. For more details, see Logging messages to a popup window. |
|
loggerName.setLogToConsole(true | false); | If set to true, the client side logger appends the messages to the browser console, for example, Firebug. If set to false (default), the messages are not appended to the browser console. |
|
loggerName.flush(); | Sends the queued messages to the z/OSMF log. You can also use the push property to push queued messages to the z/OSMF log. For more details, see Pushing messages to the z/OSMF log. |
|
Sample z/OSMF client side log data
The message entries in the z/OSMF log have a uniform structure, which is depicted in Figure 3.
2009-04-29T22:08:09.609Z|00000031|com.ibm.zoszmf.util.log.servlet.UILoggerServlet|UILoggerServlet::doPost()
FINER: [2009-04-29T22:07:13.938Z] ENTRY MYMODULE MYPACKAGE.jsp init: entry stuff
[tx0000000000002183:zosmfad@localhost (POST) /zosmf/IzuUICommon/UILoggerServlet?preventCache=1240947046138]
2009-04-29T22:08:09.609Z|00000031|com.ibm.zoszmf.util.log.servlet.UILoggerServlet|UILoggerServlet::doPost()
FINER: [2009-04-29T22:07:13.474Z] RETURN MYMODULE MYPACKAGE.jsp init: exiting stuff
[tx0000000000002184:zosmfad@localhost (POST) /zosmf/IzuUICommon/UILoggerServlet?preventCache=1240946722135]
If the log record includes an exception, the exception class and the message text are logged next followed by the traceback information that is embedded in the exception. If the exception has attached causes, each cause is also logged with "+->" indicating the start of an attached cause.