Question
Radial Inc
US
Last activity: 16 May 2018 14:24 EDT
Unable to log custom fields to PEGA logs output in JSON format
Our application is trying to write some custom fields into PEGA JSON logs in order to integrate with Logstash.
Added the following Async appenders to root logger in prlogging.xml output log files in JSON format
<appender name="JSON-ASYNC" class="com.pega.apache.log4j.AsyncAppender">
<param name="BufferSize" value="512"/>
<param name="Blocking" value="false"/>
<filter class="com.pega.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="ALERT"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
<filter class="com.pega.pegarules.priv.MDCMatchFilter">
<param name="TagToMatch" value="loggingtype" />
<param name="StringToMatch" value="Logstash" />
<param name="AcceptOnMatch" value="true"/>
</filter>
<appender-ref ref="JSONAppender"/>
</appender>
<appender name="JSONAppender" class="com.pega.pegarules.priv.util.DailySizeRollingFileAppenderPega">
<param name="FileNamePattern" value="'@{web.tmpdir}/PegaRULES-'yyyy-MM-dd'.json.log'"/>
<layout class="com.pega.pegarules.priv.LogLayoutJSON">
<param name="UserFields" value="logtimestamp: %X{@timestamp} ,requestpayload : %X{requestpayload} ,responsepayload: %X{responsepayload} ,loggingtype: %X{loggingtype} ,trackingguid: %X{trackingguid}"/>
</layout>
</appender>
Our application is trying to write some custom fields into PEGA JSON logs in order to integrate with Logstash.
Added the following Async appenders to root logger in prlogging.xml output log files in JSON format
<appender name="JSON-ASYNC" class="com.pega.apache.log4j.AsyncAppender">
<param name="BufferSize" value="512"/>
<param name="Blocking" value="false"/>
<filter class="com.pega.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="ALERT"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
<filter class="com.pega.pegarules.priv.MDCMatchFilter">
<param name="TagToMatch" value="loggingtype" />
<param name="StringToMatch" value="Logstash" />
<param name="AcceptOnMatch" value="true"/>
</filter>
<appender-ref ref="JSONAppender"/>
</appender>
<appender name="JSONAppender" class="com.pega.pegarules.priv.util.DailySizeRollingFileAppenderPega">
<param name="FileNamePattern" value="'@{web.tmpdir}/PegaRULES-'yyyy-MM-dd'.json.log'"/>
<layout class="com.pega.pegarules.priv.LogLayoutJSON">
<param name="UserFields" value="logtimestamp: %X{@timestamp} ,requestpayload : %X{requestpayload} ,responsepayload: %X{responsepayload} ,loggingtype: %X{loggingtype} ,trackingguid: %X{trackingguid}"/>
</layout>
</appender>
In a Java step of an activity in the application, we are logging the following custom field values to the LogContext
LogContext.put("requestpayload", "Request");
LogContext.put("responsepayload", "Response");
LogContext.put("trackingguid", "trackingguid");
LogContext.put("loggingtype", "Logstash");
The output in Json Logs is showing up the custom field values incorrectly
{
"@logtimestamp": "2018-05-04T18:40:55.352Z",
"logtimestamp": " %X{@timestamp} ",
"loggingtype": " %X{loggingtype} ",
"source_host": "lvsdevpega03.us.gspt.net",
"method": "?",
"level": "INFO",
"message": "System date: Fri May 04 18:40:55 UTC 2018 Total memory: 4,150,263,808 Free memory: 2,361,949,696 Requestor Count: 23 Shared Pages memory usage: 0% Current number of threads: 103",
"pegathread": "STANDARD",
"@timestamp": "2018-05-04T18:40:55.352Z",
"file": "?",
"requestpayload ": " %X{requestpayload} ",
"line_number": "?",
"thread_name": "PegaRULES-MasterAgent",
"@version": 1,
"logger_name": "com.pega.pegarules.session.internal.async.Agent",
"class": "?",
"nodeId": "a515f9a18203200a46496be8d3f1343f",
"trackingguid": " %X{trackingguid}",
"responsepayload": " %X{responsepayload} "
}
Please let us know if the approach being tried here is correct? If we are missing some steps? Could you let us know if there is a tried and tested way of writing custom fields to Json logs in PEGA?