1

I use the maven-assembly-plugin plugin to compile a fat jar. I have log4j2 and these dependencies in my pom.xml:

<dependencies>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.11.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.11.0</version>
    </dependency>
    <dependency>
        <groupId>com.sumologic.plugins.log4j</groupId>
        <artifactId>sumologic-log4j2-appender</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.2</version>
    </dependency>
</dependencies>

When I configure the logger in the log4j XML configuration file, I specify the SumoAppender and a console output appender.

When I run the main app via mvn exec:java the SumoLogic appender works.

However when I compile a fat jar and run the app via java -jar fatjar.jar, the SumoLogic Appender doesn't run at all, and there is no error that gets output.

I checked that the class exists in my app using Class.forName("com.sumologic.log4j.SumoLogicAppender") and the package indeed exists.

Does anyone know what's going on?

Aimee
  • 316
  • 2
  • 12

1 Answers1

1

I had a very similar issue - in my case mvn camel:run worked fine, but java -jar did not.

Adding the sumologic package to the log4j2 configuration file did the trick:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.sumologic.log4j">
<Appenders>
<SumoLogicAppender
....

Same strategy as when creating custom appenders - How to Create a Custom Appender in log4j2?