Custom Logs using Log-Message

Hi,

I have a requirement to create custom log file for a string match filter in Pega 23 version.

In an activity we use Log-Message method and always use a standard prefix “Custom Logging:”

The requirement is for these logs having Custom Logging as prefix need to go to a new log file instead of PegaRULES Log.

Couple of existing articles are there but there are referrred to prlogging.xml and we are using prlog4j2.

Can someone guide?

@JaikumarR1777

To create a custom log file for logs with a specific prefix in Pega 23 using prlog4j2.xml, you can follow these steps:

  1. Define a Custom Appender: Add a new appender in your prlog4j2.xml file. This appender will specify the file where the logs will be written.

<appender name=\"CustomLogAppender\" class=\"com.pega.apache.log4j.RollingFileAppender\">

<param name=\"File\" value=\"/path/to/your/custom-log-file.log\" />

<param name=\"MaxFileSize\" value=\"50MB\" />\

<layout class=\"com.pega.apache.log4j.PatternLayout\">

<param name=\"ConversionPattern\" value=\"%d [%t] %-5p %c - %m%n\" />

</layout>\</appender>

  1. Add a Logger with a Filter: Create a logger that uses the custom appender and add a filter to match the prefix "Custom Logging:"

<logger name=\"CustomLogger\" additivity=\"false\">

<filter class=\"com.pega.apache.log4j.varia.StringMatchFilter\">

<param name=\"StringToMatch\" value=\"Custom Logging:\" />

<param name=\"AcceptOnMatch\" value=\"true\" />

</filter>

<appender-ref ref=\"CustomLogAppender\" />

</logger>

  1. Update the Root Logger: Ensure that the root logger does not capture the custom logs by adding a filter to exclude them.\

<root>

<filter class=\"com.pega.apache.log4j.varia.StringMatchFilter\">

<param name=\"StringToMatch\" value=\"Custom Logging:\" />

<param name=\"AcceptOnMatch\" value=\"false\" />

</filter>

<appender-ref ref=\"PegaRULES\" />

</root>

By following these steps, logs with the prefix "Custom Logging:" will be directed to your custom log file instead of the PegaRULES log. Make sure to replace /path/to/your/custom-log-file.log with the actual path where you want the log file to be created.

:warning: This is a GenAI-powered tool. All generated answers require validation against the provided references.

Understanding PegaRULES logs

Creating log file for request-response for service calls

Issues in creating a new Custom Log