在 aws lambda 上使用 Log4J2 进行日志记录 - 找不到类
2022-09-03 05:03:39
我正在尝试使用 Log4J2 日志记录,如 AWS 文档中所述:
https://docs.aws.amazon.com/lambda/latest/dg/java-logging.html#java-wt-logging-using-log4j2.8
<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.amazonaws.services.lambda.runtime.log4j2.LambdaAppender">
<Appenders>
<Lambda name="Lambda">
<PatternLayout>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n</pattern>
</PatternLayout>
</Lambda>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Lambda" />
</Root>
</Loggers>
</Configuration>
错误但是,我在运行lambda时收到以下错误:(我删除了下面的时间戳以提高可读性)
ERROR Error processing element Lambda ([Appenders: null]): CLASS_NOT_FOUND
ERROR Unable to locate appender "Lambda" for logger config "root"
试我确保 log4J libs 和 、 和 都在包中。log4j-core
log4j-api
aws-lambda-java-log4j2
aws-lamda-java-core