3

I am getting following error while trying to use AWS lambda with log4j2. I followed all instructions given at:

https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-log4j2

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging.

Can someone please help with this?

0

1 Answer 1

3

I'm able to get this to work just fine - lets see where you're setup is different. I'm using OpenJDK 11 and the Java 11 Lambda. My Lambda handler looks like:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class LambdaHandler {
    private static final Logger logger = LogManager.getLogger(LambdaHandler.class);

    // your handler entry point may be different but that shouldn't matter
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {
    }
}

The dependencies in my pom.xml are: com.amazonaws aws-lambda-java-core 1.2.0

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-log4j2</artifactId>
        <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.13.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.13.0</version>
    </dependency>

    <dependency>
        <groupId>com.github.edwgiz</groupId>
        <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
        <version>2.8.1</version>
    </dependency>

and the build/plugins section for the shade plugin is:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.2</version>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <manifestEntries>
                            <Multi-Release>true</Multi-Release>
                        </manifestEntries>
                    </transformer>
                    <transformer
                            implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer">
                    </transformer>
                </transformers>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.github.edwgiz</groupId>
                    <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
                    <version>2.8.1</version>
                </dependency>
            </dependencies>
        </plugin>

When my Lambda starts I get the message:

WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.

I've googled this but haven't been able to fix it yet. However, it doesn't seem to hurt anything.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Stdunbar. It seems my log4j2.xml was not on class path. After fixing that it works fine.
Re: the WARNING about getCallerClass not being supported - this is because the log4j2 jar is a multi-release jar which are not supported by AWS Lambda. To fix this, see my suggestion here: stackoverflow.com/a/67978671/2404240

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.