custom module logging to a separate file on top of the usual openmrs logging

Am working on a ticket that requires custom module logging . is there currently a way we can have a module do logging in a separate file ,without adjusting the log config in the openmrs core?? i would want some thing like this placed in a module , rather than adjusting the core’s log config

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
   <appender name="Reporting_DEBUGGING_FILE_APPENDER" class="org.apache.log4j.RollingFileAppender">
     <param name="append" value="false"/>
     <param name="file" value="Reporting.log"/>
     <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
     </layout>
  </appender>
  
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>

   <logger name="org.openmrs.module.Reporting" additivity="false">
   	<level value="INFO" />
   	<appender-ref ref="Reporting_DEBUGGING_FILE_APPENDER"/>
   	<appender-ref ref="Console" />
   </logger>
   
   <root>
   	<appender-ref ref="Reporting_DEBUGGING_FILE_APPENDER" />
   	<appender-ref ref="Console" />
   </root>
</log4j:configuration>

i have tried to place it in the module , but it seems not to work. Help needed

cc @k.joseph @dkayiwa @samuel34 @tendomart @wyclif

thanks @k.joseph. Let me have a look at it

hello @k.joseph, i have looked at that talk thread. But it seems your advise was to add the custom module log config , to the openmrs core log4j config file. please correct me if I have misunderstood the suggestion you gave .

am not sure if log4j2 supports multiple configuration files but my search seems not to suggest that it does, the quickest way would be adding your appender in the openmrs log4js configuration file

not sure, i think multiple config files weren’t supported when i looked into this, am not sure if it is right now. if this was an implementation specific thing, i would improvise by a symbolic link (ln -s) to a clone of the same config file in openmrs so that the existing one points to my other one (clone) that adds my other appenders; i have not tried this out; java.nio.file.Files.createSymbolicLink(symLinkPath, existingFilePath); not sure if it can help. you could try it in your module’s activator.

thanks @k.joseph. let me try it out

@mozzy any update on this?

@mksd , i used a symbolic link and it worked. just that later i discovered , custom logging was already implemented , and i only had to add a user interface component to search and view the logs

@mozzy can you throw some more light on this point?

@ivange94 , i was working onthis ticket https://issues.openmrs.org/browse/REPORT-770?filter=-1 which required creatint a custom looging for the repoerting module and also adding a UI componentfor the logs. but i discovered work on creating the custom logging had already been done , and i only had to create a UI component for the module

Thanks @mozzy. I got that. What I was actually asking is, where is this work already done and how do I test it?

I have no idea if that’s the one @mozzy is talking about, but there is this old module (depending on Core 1.7.x): https://github.com/rowanseymour/openmrs-module-logmanager/

Who knows…

@mksd i was not necesarilly talking modules that do custom logging like that one , my task was to specifically make the reporting module do some custom logging, to log therepoerting activities.

@ivange94, are you exactly asking about the reporting module doing custom logging ?? but it only does its own logging for the reporting activities, not that it can support other modules to also do custom logging

the custom loging for the reporting module am talking about was done here https://issues.openmrs.org/browse/REPORT-329

@mozzy this ticket was closed with no commits made.

Anyway the answer is that we are not interested in custom logging specifically in the Reporting module. Ideally we would want this for any module upon configuration.

@mksd i get you now.

that could be better

ya that true , no commits were made , but in the comments, @mseaton gave directives on how it was done , and it is what i used to build upon to work on this ticket https://issues.openmrs.org/browse/REPORT-770?filter=-1