Associating a Diagnostic Provider ID with a logger
If you 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.
About this task
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
Procedure
Logger logger = Logger.getLogger("com.ibm.ws.MyClass");
DiagnosticProviderHelper.addDiagnosticProviderIDtoLogger(logger, dpid);
Dynamic Assignment
About this task
Object[] parms = new Object[] { "DPID:" + dpid };
logger.logp(classname, methodname, "MSG0001", parms);
(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 previously, this is done by not including {0} in the message value in the resource bundle.