Search code examples
mulemule-studioanypoint-studiomulesoft

Add More Logger on Mulesoft 3.9


i want to add another logger to save only request and response messages different than default logger. Default Logger i still using to save all process of my flow. Anyone have idea how to add another log? Notes: A new logger will write into the new log file not same with default.


Solution

  • You need to add a new file appender to the log4j2.xml and add loggers that reference it instead of the default root logger.

    log4j2.xml:

    <Appenders>
        ...
        <RollingFile name="another-file" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}other.log" 
                 filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}other-%i.log">
            <PatternLayout pattern="%-5p %d [%t] [processor: %X{processorPath}; event: %X{correlationId}] %c: %m%n" />
            <SizeBasedTriggeringPolicy size="10 MB" />
            <DefaultRolloverStrategy max="10"/>
        </RollingFile>                
    </Appenders>
    <Loggers>
    ...
        <!-- Mule set a category package only to the new appender -->        
        <AsyncLogger name="com.mycompany.project.module" level="INFO" additivity="false">
            <AppenderRef ref="another-file" />
        </AsyncLogger>
    

    In the Mule application use the category of the loggers to determine to which file it will be sent:

        <logger level="INFO" doc:name="Logger" message="default log"/>
        <logger level="INFO" category="com.mycompany.project.module" doc:name="Log to second logger" message="another log" />