" ... practice makes perfect "      - stellentpmp aka Andrew
stellentpmp.blogspot.comContent Server

Monday, March 7, 2011

Create your own Tracing Section

If you've written custom java filters, idoc scripts, or services, you've probably added some basic logging using SystemUtils.trace("system", "log message");. However, wouldn't it be nice to separate your logs by creating your own UCM tracing section (GET_SYSTEM_AUDIT_INFO)?  It's easier than you think.


In your component definition (.hda) file, add the following:

... to the ResourceDefinition table

resource
resources/custom_resources.htm
customTraceSections
500


... to the MergeRules table:

customTraceSections
IdcTracingSections
itsSection
1


... to the resource file defined above (ie. custom_resources.htm):

<@table customTraceSections@>
<table border="1"><caption><strong>Custom Tracing Sections</strong></caption>
<tr>
    <td>itsSection</td>
    <td>itsDescription</td>
    <td>itsDefaultEnabled</td>
</tr>
<tr>
    <td>customTraceName</td>
    <td>trace custom component</td>
    <td>false</td>
</tr>
</table>
<@end@>


Then change either of the following to suit your needs:
  1. "customTraceName" to the name you want to use for your tracing section.  This is what appears within the tracing section dropdown list.
  2. itsDefaultEnabled to "true" if you want your tracing section to be active/turned on after restarting the content server.

At this point, your tracing section is set up and ready to be used by your java code (after restart).

First, be sure to include the SystemUtils class:

import intradoc.common.SystemUtils;


Then simply add tracing like this:

SystemUtils.trace("customTraceName", "Thanks stellentpmp!");


or like this if you want to utilize "Full Verbose Tracing":

if (SystemUtils.m_verbose)
{
    SystemUtils.trace("customTraceName", "Thanks stellentpmp for everything!");
}


Good luck.

No comments:

Post a Comment