Question
Amazon
Last activity: 25 May 2016 13:00 EDT
Custom Appender - Thread Info
Hello All,
We have written a Custom Appender. We loaded the JAR into PRPC, updated prlogging.xml and able to create a new log file altogether. Now, we want to read data from a clipboard page / page list / database table rule from our custom Java Appender Code. How can we do this? What is the starting point?
We have error message, severity etc. info in LogEvent. How to find out the thread, user, application name when a log event occurs?
Any help is much appreciated. Thanks in advance.
Regards
Shiva
Message was edited by: Marissa Rogers - Updated category
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Incessant Technologies
IN
How to find out the thread, user, application name when a log event occurs?
All these information are available in some prebuilt pages like -
Application (Rule-Application) page has current application information.
pxRequestor ( Code-Pega-Requestor) has requestor information like user name, label etc.
pxThread (Code-Pega-Thread) has information about thread.
You can see more information about these pages in clipboard under system pages.
Amazon
Hi Rajesh,
Thanks for your reply. What you suggested works when I am connected to the browser. I want to read this information from Custom Java Appender.
Whenever an exception/error occurs, Pega is giving control to the custom Java Appender (Custom JAR). From Custom Java Appender, I want to know thread info, application name, query records from database rule, invoke/call PRPC rules, read Clipboard pages etc. How can I achieve this?
Any help is much appreciated.
Regards
Shiva
Amazon
I tried the below code in Java Method of Custom JAR written by me
PRThread thisThread = (PRThread)ThreadContainer.get();
if (thisThread != null)
{
tools = thisThread.getPublicAPI();
}
else
{
msgToReturn = "better luck next time";
}
thisThread is NULL. Hence, I am unable to use PegaAPI / PublicAPI. Any help is much appreciated.
Thread name, requetorID, application name etc are saved on LogContext, you can use the static method com.pega.pegarules.priv.LogContext.get(String) to get these values from your custom appender.
For example, to fetch userid you can call LogContext.get("userid"), the exact names to use are hardocoded in the class com.pega.pegarules.session.internal.engineinterface.service.HttpAPI.
Amazon
Hello Chaitanya,
Thanks for your response. That solves my problem to some extent. I also have the need to invoke PRPC rules from Custom Java Appender. For this, I need PegaAPI or PublicAPI instantiation which is done as mentioned in my above replies. How can I achieve this?
Regards
Shiva
Amazon
PRThread thisThread = (PRThread)ThreadContainer.get();
if (thisThread != null)
{
tools = thisThread.getPublicAPI();
}
else
{
msgToReturn = "better luck next time";
}
This approach of instantiating PegaAPI is not working.
Hi Shiva,
You cannot invoke PRPC rules from Custom Appender, I am not sure why you would want to invoke PRPC rules from a Custom Appender, can you elaborate your use case please?
Thanks,
Chaithanya
Amazon
Hi Chaitanya,
We have multiple applications running in PROD. Based on the application which caused Error/Exception, we want to push some application specific data/values to be pushed into logs for our critical reporting needs. We maintain this application specific info in a Data Type rule (Database table). At the same time, we want to read some data from the User's clipboard pages / System level Clipboard pages whenever an Error/Exception is caused by an Operator. This is also for supporting for our critical reporting needs.
That's why, in short, I mentioned as "How to invoke PRPC rules" which could have caused some confusion. I hope this clarifies.
Regards
Shiva
Pegasystems Inc.
GB
Hi Shiva,
I took a quick read of this post: and it's not quite clear to me what you need here, but let me 'play back' what my understanding is here of your requirement.
1. You have already created a customer log4j appender.
2. You have already got this working from PRPC (which uses a customized version of log4j): I think ?
3. You want this Appender to 'reach into' PRPC and execute some rules; and get the information returned ?
Here's what I'm unsure about:
When you say:
We have multiple applications running in PROD. Based on the application which caused Error/Exception, we want to push some application specific data/values to be pushed into logs for our critical reporting needs
I assume you mean 'PRPC applications' here.
So I think you are saying that if a PRPC Application Error occurs; you need to capture additional PRPC-specific information relating to the PRPC Clipboard etc ?
Do you mean in the same way that PRPC Alerts (which also use log4j) contain PRPC-specific information ?
You seem to have a secondary and (as far as I can see, separate) requirement:
At the same time, we want to read some data from the User's clipboard pages / System level Clipboard pages whenever an Error/Exception is caused by an Operator.
Hi Shiva,
I took a quick read of this post: and it's not quite clear to me what you need here, but let me 'play back' what my understanding is here of your requirement.
1. You have already created a customer log4j appender.
2. You have already got this working from PRPC (which uses a customized version of log4j): I think ?
3. You want this Appender to 'reach into' PRPC and execute some rules; and get the information returned ?
Here's what I'm unsure about:
When you say:
We have multiple applications running in PROD. Based on the application which caused Error/Exception, we want to push some application specific data/values to be pushed into logs for our critical reporting needs
I assume you mean 'PRPC applications' here.
So I think you are saying that if a PRPC Application Error occurs; you need to capture additional PRPC-specific information relating to the PRPC Clipboard etc ?
Do you mean in the same way that PRPC Alerts (which also use log4j) contain PRPC-specific information ?
You seem to have a secondary and (as far as I can see, separate) requirement:
At the same time, we want to read some data from the User's clipboard pages / System level Clipboard pages whenever an Error/Exception is caused by an Operator.
Do you mean you literally need to 'call-back' to PRPC and request further information here ?
If so: this sounds (in theory) acheivable by using PRPC 'Services' - say a SOAP Service, or a REST Service ?
It doesn't sound a good idea to me (I could be wrong) to make SOAP/REST calls *from* a log4j appender to a service though: not least because of the latency that would cause.
(Appenders should be *writing* somewhere really; in theory they could do *anything* that you can do in Java, but do you really want to use an Appender to do this ? It sounds like 'feature-creep' ?, dunno)
Perhaps you could illustrate what you need here in your Log Files: exactly what PRPC information you need in the output ?
Thanks,
John
Amazon
Hello John,
Thanks for replying.
Your understanding mentioned as below is right.
I meant multiple PRPC applications by referring to many applications in PROD
PRPC Specific Information :
Hello John,
Thanks for replying.
Your understanding mentioned as below is right.
I meant multiple PRPC applications by referring to many applications in PROD
PRPC Specific Information :
Yes John, your understanding is right. Whenever an error occurs, we want additional PRPC-specific information which we may wish to read from PRPC Clipboard (User, System pages etc.) or Data Type rules i.e. mapped to a DB Table. Yes, just like PRPC Alerts (we see very limited information)
Call-back to PRPC :
Yes, I meant 'Call-Back' to PRPC and request further information. SOAP / REST service can be used by relying purely on JAVA API but leveraging PRPC PublicAPI / PegaAPI i.e. tools object initialization provides better control to call/execute PRPC rules.
For each PRPC application, we have our environment specific properties, business specific properties maintained in a DB Table / Data Type rule. We also have a reporting tool which can report on a log file with it's own specific format i.e. Key Value Pair format. This reporting tool needs additional properties to be present in the log file which we can only get from either Clipboard OR by executing/calling PRPC rules from Custom Log Appender whenever an Error / Exception occurs.
I hope this clarifies. If not, please let me know.
Regards
Shiva
Pegasystems Inc.
GB
Hi Shiva,
Access the database table and clipboard to write one single log entry to a file may take time to complete, in the mean time the Application will continue to write log entries, there is a chance that the log4j buffer size may need to be increased to accommodate the log entries while you fetch additional data for the first one. this doesn't seems scalable approach, and may have chance to loose logentry in case db query fails.
Instead of a database table, you could store the information in LogContext map
you could add new fields and corresponding data in LogContext using LogContext.put("newfield1", "myFielddata");
and write the data in the log by using a log pattern like below, you could use the existing appender here.
<param name="ConversionPattern" value="%d [%20.20t] [%10.10X{pegathread}] [%20.20X{tenantid}] [%20.20X{app}] (%30.30c{3}) %-5p %X{stack} %X{userid} %X{newfield1} - %m%n"/>
Amazon
Hello,
Any help is much appreciated.
Regards
Shiva