bluedenim/log4j-s3-search

Error processing element Log4j2Appender ([Appenders: null]): CLASS_NOT_FOUND

nikhithareddy-modak opened this issue · 5 comments

I have added the therealvan dependencies in my JAVA project pom.xml ,I have build the jar and ran the code,then I got the error

2020-11-20 14:48:54,581 main ERROR Error processing element Log4j2Appender ([Appenders: null]): CLASS_NOT_FOUND
2020-11-20 14:48:54,757 main ERROR Unable to locate appender "Log4j2Appender" for logger config ""
2020-11-20 14:48:54,758 main ERROR Unable to locate appender "Log4j2Appender" for logger config ""

I have used all the versions including the latest version 2.8.3

I think it's just a configuration issue. Here's a sample project that should get you started:

log4j2.zip

Here's how to exercise it after expanding:

cd <where log4j2.zip was expanded>
mvn install

cd target
java -cp log4j-s3-search-log4j2-sample.jar example.App

The output of running the program:

15:49:30,852 [main] INFO  example.App - Hello from Main!
15:49:30,857 [main] INFO  example.App - Another round through the loop!
15:49:30,857 [main] WARN  example.App - This is a warning!
15:49:30,857 [main] ERROR example.App - And this is an error!!!
15:49:33,870 [main] INFO  example.App - Another round through the loop!
15:49:33,870 [main] WARN  example.App - This is a warning!
15:49:33,870 [main] ERROR example.App - And this is an error!!!
15:49:36,877 [main] INFO  example.App - Another round through the loop!
15:49:36,877 [main] WARN  example.App - This is a warning!
15:49:36,877 [main] ERROR example.App - And this is an error!!!
15:49:39,884 [main] INFO  example.App - Another round through the loop!
15:49:39,884 [main] WARN  example.App - This is a warning!
15:49:39,886 [main] ERROR example.App - And this is an error!!!
15:49:42,898 [main] INFO  example.App - Another round through the loop!
15:49:42,898 [main] WARN  example.App - This is a warning!
15:49:42,898 [main] ERROR example.App - And this is an error!!!
LoggingEventCache com.van.logging.LoggingEventCache@27c6e487: shutting down
LoggingEventCache: Executor service terminated within timeout: true
CapacityBasedBufferMonitor: shutting down.

Can you please explain the sentence "Exclude all the transitive dependencies to external libs so we get to specify the versions we want ", that you have written in pom.xml

Sure. So when I built appender-core, for example, I used com.amazonaws:aws-java-sdk:1.11.613 (see https://github.com/bluedenim/log4j-s3-search/blob/master/pom.xml#L46-L50).

So if you don't change anything, when you depend on com.therealvan:appender-log4j2:2.8.3, it depends on com.therealvan:appender-core:2.8.3, and that depends on com.amazonaws:aws-java-sdk:1.11.613. So the transitive dependency of your program now includes com.amazonaws:aws-java-sdk:1.11.613.

When I do this:

                <exclusion>
                    <groupId>com.amazonaws</groupId>
                    <artifactId>aws-java-sdk-s3</artifactId>
                </exclusion>

It removes com.amazonaws:aws-java-sdk:1.11.613 from your final project. This will allow you to now add the version of com.amazonaws:aws-java-sdk-s3 that you want. Maybe you want a newer version of AWS S3 SDK than 1.11.613. Instead of waiting for me to update my library, you can:

  • Add the exclude above, then
  • Add the dependency to the version of AWS S3 you want (maybe 1.11.907) in your pom.xml

https://www.educba.com/maven-exclude-dependency/ explains it better if you want details.

Thank you! My issue got solved it was because of not using latest dependencies of log4j2 and also for not included maven shade plugin in pom.xml