Can PatternLayout be used with HTTP appender in log4j2.xml?

Viewed 24

We have a requirement to push our application logs to ELK from the Mule applications in CloudHub. For this, I am using ELK configs in the log4j HTTP appender.

Below is the log4j Config in my mule application app1:

<?xml version="1.0" encoding="utf-8"?>
<Configuration>

    <!--These are some of the loggers you can enable. 
        There are several more you can find in the documentation. 
        Besides this log4j configuration, you can also use Java VM environment variables
        to enable other logs like network (-Djavax.net.debug=ssl or all) and 
        Garbage Collector (-XX:+PrintGC). These will be append to the console, so you will 
        see them in the mule_ee.log file. -->

    <Appenders>
        <RollingFile name="file" fileName="/logs/mule/application/app1.log" 
                 filePattern="/logs/mule/application/app1-%d{dd-MMM-yyyy}-%i.log">
            <PatternLayout pattern="%-5p %d [%t] [event: %X{correlationId}] %c: %m%n" />
            <SizeBasedTriggeringPolicy size="10 MB" />
            <DefaultRolloverStrategy max="20"/>
        </RollingFile>
         <Http name="ELK" url="https://<url to elk>/mule-cloudhub-logs/_doc">        
           <JsonLayout compact="true" eventEol="true" properties="true" />
           <Property name="kbn-xsrf" value="true" />
           <Property name="Content-Type" value="application/json" />           
           <Property name="Authorization" value="ApiKey apikey" />
           <PatternLayout pattern="%-5p %d [%t] [event: %X{correlationId}] %c: %m%n" />
        </Http>
    </Appenders>
    <Loggers>
        
        <!-- Http Logger shows wire traffic on DEBUG. -->
        <!--AsyncLogger name="org.mule.service.http.impl.service.HttpMessageLogger" level="DEBUG" /-->
        <AsyncLogger name="org.mule.service.http" level="WARN"/>
        <AsyncLogger name="org.mule.extension.http" level="WARN"/>
    
        <!-- Mule logger -->        
        <AsyncLogger name="org.mule.runtime.core.internal.processor.LoggerMessageProcessor" level="INFO"/>
 
        <AsyncRoot level="INFO">
            <AppenderRef ref="file" />
            <AppenderRef ref="ELK" />
        </AsyncRoot>
    </Loggers>
</Configuration>

Now, the output in ELK for this, comes out to be :

[MuleRuntime].uber.08: [app1].get:\v1\dummy\uri:app1-config.CPU_INTENSIVE @232321

No matter what kind of pattern I put in the PatternLayout in the HTTP appender, the output is still the same in elk.

Additionally, when am deploying the application, the deployment logs show a one line error as below :

2022-09-15 12:54:09,270 WrapperListener_start_runner ERROR appender Http has no parameter that matches element PatternLayout

Is there is an issue in my config or some other bug?

1 Answers

You can define only 1 layout per Appender. Your Http appender has two, the JsonLayout and PatternLayout

Related