Skip to Content
Author's profile photo vishal javalkar

Adding Audit Log in PI Mapping UDF in PI Single Stack

Hi Guys,

Perhaps this is not a new topic , however I thought quickly consolidating all the steps required for adding a audit log entry from PI user defined function. Hope it will be helpful.

Before we go to the steps lets quickly go through the difference between Trace Vs Audit Log.


Entries added using the Trace object are added in the logs and traces, which can be viewed in  NWA -> Troubleshooting -> Logs and Traces -> Log Viewer application and are not part of the  Message Log often referred as Audit log of a message.


Entries added using Audit object are added in the Message Logs (Audit Logs) and are associated  with a message and viewed from message monitor.

Step 1 : Download a from PI server ( you can ask your basis team to provide it) and import in your ESR namespace as imported archive object. This jar is required to access the Audit and MessageKey class in the UDF at the compile time.

Step 2: Add the imported archive in the UDF ‘Archive Used’ tab.

Step 3: Add class* and* under import tab.

Step 3: Use the below code snippet to add the audit log entries in the UDF

MessageKey key = null

AuditAccess audit = null;

final String DASH = “-“;


    String msgID=container.getInputHeader().getMessageId();

    String uuidTimeLow = msgID.substring(0, 8);  

    String uuidTimeMid = msgID.substring(8, 12);  

    String uuidTimeHighAndVersion = msgID.substring(12, 16);  

    String uuidClockSeqAndReserved = msgID.substring(16, 18);  

    String uuidClockSeqLow = msgID.substring(18, 20);  

    String uuidNode = msgID.substring(20, 32);  

    String msgUUID =   uuidTimeLow + DASH + uuidTimeMid + DASH + uuidTimeHighAndVersion + DASH  + uuidClockSeqAndReserved + uuidClockSeqLow + DASH + uuidNode;

    audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();

    key = new MessageKey(msgUUID, MessageDirection.OUTBOUND);

    audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, “Audit Log entry added successfully !!”);


catch(Exception ex){

    throw new StreamTransformationException(“Exception Occured”,ex);


Thats all , now you can run a message verify if the entry ” Audit Log entry added successfully !!”  in you message log/audit log.

Hope this provides a quick reference for adding audit logs.

Vishal Javalkar

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Azhar Shaikh
      Azhar Shaikh

      Hi Vishal,

      Very well explained 🙂 .



      Author's profile photo Eng Swee Yeoh
      Eng Swee Yeoh

      Hi Vishal

      Looks like this has already been covered in the following blog a year ago.

      Writing Log Entries to Audit Log of the Message from Custom Java Mapping Program

      Even the code looks strikingly similar with same variable declarations. Perhaps you can consider adding original content to it, as well as giving credit and reference to the original post.


      Eng Swee

      Author's profile photo Former Member
      Former Member

      Hi Vishal,

      I am working on a scenario where I need to retrieve Audit logs of message based on message key. Do we have any classes to retrieve audit logs of message.

      Thanks in Advance,

      Ramanji Killani.

      Author's profile photo Vadim Klimov
      Vadim Klimov

      Hello Ramanji,

      I made a suggestion on options that can be used to address your requirements earlier today, as a reply to your comment in the blog Writing Log Entries to Audit Log of the Message from Custom Java Mapping Program, and have just seen you had posted same question here. Not to make different community members potentially do double work when finding your question and commenting on it in various locations in SCN, would you mind considering creation of a dedicated forum thread for the future (or maybe for current question, too, if you have any further concerns)?



      Author's profile photo Eng Swee Yeoh
      Eng Swee Yeoh

      I'd suggest using the "Alert Moderator" link to highlight the comment as cross-posting or posting an issue in a blog comment which should have been raised as a thread. 😉