Class file to create custom header using log4j2 wrapped up into Jar and deployed to Tomcat no longer works

Viewed 19

I have created a web application and deployed it to tomcat 9. The application uses log4j2 to log message to a file. I created a class called MyLookup and extended the AbstractLookup class to overwrite the lookup method to get a customised header message. The MyLookup.class lives in {apache-tomcat-instance}\webapps\{webapplication-instance}\WEB-INF\classes
This is all working as expected, but when I package the MyLookup class into a jar file and deployed to:

{apache-tomcat-instance}\webapps\{webapplication-instance}\WEB-INF\lib\ along with my other jars for our staging environment, Instead of getting the customised header text, I get the following text:

${headerlookup:header}

Which is the input value for header as shown below: But if I manually extract MyLookup back to \classes\ it work as before.

My log4j2.xml looks like this:

<RollingFile name="Appender">
    <FileName>file.xml</FileName>
    <PatternLayout header="${headerlookup:header}">
        <Pattern>%msg</Pattern>
    </PatternLayout>
    <Policies>
        <SizeBasedTriggeringPolicy size="6MB" />
    </Policies>
</RollingFile>

and my simplified MyLookup class looks like this:

@Plugin(name = "headerlookup", category = StrLookup.CATEGORY)

    public class MyLookup  extends AbstractLookup {
        
    
        @Override
        public String lookup(LogEvent arg0, String arg1) {
            
            return "some customised header result";
            
        }
        
    }

Does anyone know what I've done wrong?

0 Answers
Related