amazon-web-services - 将 log4j2 与 AWS Lambda 结合使用

标签 amazon-web-services aws-lambda log4j2

我在尝试将 AWS lambda 与 log4j2 结合使用时遇到以下错误。我遵循了以下网址给出的所有说明:

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.

有人可以帮忙吗?

最佳答案

我能够让它正常工作 - 让我们看看您的设置有何不同。我正在使用 OpenJDK 11 和 Java 11 Lambda。我的 Lambda 处理程序如下所示:

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) {
    }
}

我的 pom.xml 中的依赖项是: com.amazonaws aws-lambda-java-核心 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>

shade 插件的 build/plugins 部分是:

        <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>

当我的 Lambda 启动时,我收到消息:

警告:不支持 sun.reflect.Reflection.getCallerClass。这会影响性能。

我用谷歌搜索过这个问题,但还没有解决它。然而,它似乎并没有伤害任何东西。

关于amazon-web-services - 将 log4j2 与 AWS Lambda 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61097136/

相关文章:

amazon-web-services - 无法访问 Docker swarm 中的服务

amazon-web-services - 来自 AWS 的 nginx 日志说 "HELP...batman"?

amazon-web-services - 如何处理来自 API 网关的 lambda 错误

java - Jboss 6.4 上的 Log4j 2 自定义级别

java - 当我增加 tomcat 上的负载时,log4j2 ParameterFormatter.appendCollection 中出现 ConcurrentModificationException

amazon-web-services - 使用 CloudFormation 添加对 AWS websocket API 的集成响应

amazon-web-services - API 网关映射模板可选字段

amazon-web-services - 在 Lambda 中创建 AmazonS3Client 时出现 OutOfMemoryError

postgresql - 使用 AWS Lambda 和 Golang 连接到 AWS RDS PostgreSQL

java - 过滤掉 Log4j2 文件中的 Hibernate 日志