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

Implement Custom logger in prlog4j2.xml

SA-55477

Summary



When implementing a custom logger for an activity, the logger is enabled in the prlogging.xml file. However, when moving the changes  to prlog4j2.xml file, additional information is logged to the output file. This occurs after updating to Pega 7.3.1.


Error Messages



Not Applicable


Steps to Reproduce

  1. Update Pega 7.1.7 to Pega 7.3.1.
  2. Implement custom logger for an activity in prlog4j2.xml.
  3. Verify the output file which contains additional logging information..


Root Cause



A defect or configuration issue in the operating environment.

The issue was in configuration of prlog4j2.xml file where the logger was also referenced in the async root and by default, the root logger logs the log message for the whole application.

asyncRoot - Root logger  that logs messages for all classes in the application.

Note: By default,  Log4j assigns the root logger to Level.ERROR.

The default out-of-the-box (OOTB) logger (as present in the default prlog4j2.xml OOTB version) for the root logger are as below:


<asyncRoot
<AppenderRef ref="CONSOLE"/> 
<AppenderRef ref="PEGA"/> 
<AppenderRef ref="ALERT" level="ALERT"/> 
<AppenderRef ref="ALERTSECURITY" level="ALERT"/> 
</asyncRoot


Package or class of a logger is defined in the prlog4j2.xml by the attribute "name". Inorder to add any logger for a package or class, define the logger.

For example,

 
<Logger name="com.pega.pegarules.session.internal.mgmt.SecurityEventLogger" additivity="false" level="info"> 
<AppenderRef ref="SECURITYEVENT"/> 
</Logger> 


In log4j, a logger is associated with a package or with a particular class. A logger logs messages in its package and in all the child packages and their classes. The only exception is the root logger that logs messages for all the classes in the application. Hence, AppenderRef must not be included in the asyncRoot tag.


Resolution



Perform the following local-change:
  1. Add a section for RollingRandomAccessFile in the Appenders tag as below.

    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="warn">
      <Appenders>
        ------------------
        ------------------
        <RollingRandomAccessFile name="PEGATESTLOGGER" fileName="${sys:pega.logdir}/PEGATESTLOGGER-Activity.log" filePattern="${sys:pega.logdir}/PEGATESTLOGGER-Activity-%d{MM-dd-yyyy}-%i.log.gz">
          <PatternLayout>
            <Pattern>%m%n</Pattern>
          </PatternLayout>    
          <Policies>
            <TimeBasedTriggeringPolicy/>
            <SizeBasedTriggeringPolicy size="50 MB"/>
          </Policies>
        </RollingRandomAccessFile>
        ------------------  
    </Appenders
    >
     
  2. Do not  add AppenderRef in the asyncRoot tag. Adding AppenderRef in the asyncRoot logs messages for all classes in the log file.
  3. The package or class of the logger is defined in the prlog4j2.xml by the attribute 'name'. Fetch the logger name for the activity or class and add it in the Loggers tag as below.

      <Loggers>
        <asyncRoot>
          <AppenderRef ref="CONSOLE"/>
          <AppenderRef ref="PEGA"/>
          <AppenderRef ref="ALERT" level="ALERT"/>
          <AppenderRef ref="ALERTSECURITY" level="ALERT"/>
        </asyncRoot>
        -----------------
        -----------------
        <Logger name="Rule_Obj_Activity.PegaTestLogger.GCS_GCSAPP_Work.Action" additivity="false" level="info">
          <AppenderRef ref="PEGATESTLOGGER"/>
        </Logger>
        -----------------
      </Loggers>
    </Configuration>
 

Published January 26, 2019 - Updated October 8, 2020

Was this useful?

100% 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