Skip to content

Issues in Logging AWS Lambda Application with Log4j2 #137

@MounicaRamini

Description

@MounicaRamini

I have an AWS Lambda Function, when executed gives errors related to reading Log4j2 file on cloudWatch.
I have log4j2 configuration related to AWS Lambda Logging

@spaethp Could you please help me resolve the below error

2019-10-01 14:39:54,029 main ERROR Error processing element Lambda: CLASS_NOT_FOUND
2019-10-01 14:39:54,031 main ERROR Unable to locate plugin type for Lambda
2019-10-01 14:39:54,054 main ERROR Unable to locate plugin for Lambda
2019-10-01 14:39:54,056 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.config.AppendersPlugin for element Appenders: java.lang.NullPointerException java.lang.NullPointerException
.
.
.
.
2019-10-01 14:39:55,839 main ERROR AppenderRef contains an invalid element or attribute "_ref"
2019-10-01 14:39:55,840 main ERROR Appender references must contain a reference
2019-10-01 14:39:55,893 main ERROR Null object returned for AppenderRef in Root.
2019-10-01 14:39:55,894 main ERROR Root contains an invalid element or attribute "_level"
2019-10-01 14:39:59,837 main ERROR Error processing element Lambda: CLASS_NOT_FOUND

Here is my Log4j2.YAML Configuration

Configuration:
 Appenders:
  Lambda:
   PatternLayout:
    pattern: "%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n"
   _name: Lambda
 Loggers:
  Root:
   AppenderRef:
    _ref: Lambda
   _level: info
 _packages: "com.amazonaws.services.lambda.runtime.log4j2.LambdaAppender"

Here is my Maven POM for Logging Dependencies

<dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-log4j2</artifactId>
            <version>1.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.12.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.12.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.12.0</version>
        </dependency>

        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>1.25</version>
        </dependency>
        
       <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>2.9.9</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.9</version>
        </dependency>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>**/Log4j2Plugins.dat</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions