Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Unable to get MDC fields for custom logging

SA-33123

Summary



User is trying to implement a custom logging appender to send log messages to a log aggregator (that is, splunk).

User wants to capture the userID, thread and requestorID, that are currently logged in the file log appenders in prlogging.

These values are MDC fields, and so user is trying to capture them with MDC.get methods, however, the user has been unsuccessful in obtaining any value from the MDC.


Error Messages



Not Applicable


Steps to Reproduce



Implement a custom appender and have the appender try to retrieve a value for MDC pegathread or userID by using any of the following methods:

String mdcValue = LogContext.get("pegathread"); --using LogContext
String mdcValue = MDC.get("pegathread"); --using MDC class

Each time the mdcValue variable is always null.


Root Cause

As it is a AsyncAppender, the Appender append() is called on a separate dispatcher thread.

Hence, MDC.get() returns null.

What AsyncAppender does is that it stores a copy of the MDC in the LoggingEvent when AsyncAppender.doAppend() is called on the original thread itself.

So, value of any MDC key can be fetched via event.getMDC(key).



Resolution



The following change helps address the issue:

Object val = event.getMDC("pegathread");

Published March 9, 2017 - Updated October 8, 2020

Was this useful?

0% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us