Log4J pattern's overwritten by OpenMRS

Application Name: Reference Application 2.3, Platform 1.11.x

Question: I am trying to create/maintain a rolling file application event log for a patient portal module, where every action/event of the patient can be logged to better understand the user behavior in the application.

I am able to create a rolling file appender by adding these lines in the log4j.xml :

<appender name="PPTLogs" class="org.apache.log4j.RollingFileAppender">
    <param name="append" value="false"/>
    <param name="maxFileSize" value="100KB" />
    <param name="maxBackupIndex" value="5" />
    <param name="file" value="/usr/share/tomcat6/.OpenMRS/pptinfo.log"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss,SSS zzz} %p %c{1} %m %n"/>

<logger name="org.openmrs.module.patientportaltoolkit">
<level value="INFO" />
<appender-ref ref="PPTLogs"/>

The problem is the Conversion Pattern - Any pattern I include in the ConversionPattern param would be overwritten by the OpenMRS conversion pattern included in the global properties

log.layout = %p - %C{1}.%M(%L) |%d{ISO8601}| %m%n

Am I missing something? or is OpenMRS overwriting any/all appender patterns using the global properties? If yes, is there a workaround where modules can use their own pattern’s to create rolling files to create logs

Can you set the global property to the value which takes care of your module?

1 Like

Yep, that works - but it modifies it for everything, wanted to see if there was a way to do it only for a specific appender/module.

Off the top of my head, modules are not supposed to ship with a log4j.xml file because that messes up logging for the entire application