WAS v8.5 > Troubleshoot > Work with Diagnostic Providers

Associate a Diagnostic Provider ID with a logger

If we are using a Diagnostic Provider to manage alerts and messages, you need to associate the Diagnostic Provider ID with a logger. This can be done dynamically or through a static assignment. Components whose diagnostics are managed through a Diagnostic Provider MBean should include the Diagnostic Provider ID (DPID) in all logged messages. In some cases a single logger always logs with the same DPID. In those cases, it is appropriate to statically associate the DPID with the logger. In other cases, a logger might log on behalf of various diagnostic domains. For example, although every data source has a separate Diagnostic Provider MBean, they all share the same logger. In those cases, the DPID can be dynamically supplied on each logging call.


Static Assignment

About this task

The method below statically assigns a DPID to a logger.

Procedure

Associate a DPID with a logger:

Logger logger = Logger.getLogger("com.ibm.ws.MyClass");
DiagnosticProviderHelper.addDiagnosticProviderIDtoLogger(logger, dpid);


Dynamic Assignment

About this task

DPIDs can be associated with a single log request by including them as the first message parameter, prefixed with DPID:. To associate a DPID with a single log request using a logger:

Object[] parms = new Object[] { "DPID:" + dpid };
logger.logp(classname, methodname, "MSG0001", parms);

Note that in the dynamic case, the DPID does not need to actually show up in the formatted message. The two examples below illustrate:

(in resource bundle)
// by not including {0} first parm is not printed in the message.
MSG0001=This message does not include the DPID.   

// note - it is not recommended to print the DPID in your message.
MSG0002=This message includes the DPID...it's value is {0}. 

It is recommended that messages not include the DPID in the formatted message. As shown above, this is done by not including {0} in the message value in the resource bundle.


+

Search Tips   |   Advanced Search