在aws lambda上使用Log4J2进行日志记录 - 找不到类 [英] Logging using Log4J2 on aws lambda - Class not found
问题描述
我正在尝试使用AWS文档中所述的Log4J2日志记录:
I am trying to use Log4J2 logging as described here in the AWS docs:
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 However I am getting the following error when running the lambda: (I removed timestamps below to improve readability)
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
都在包中。
Tried
I made sure that the log4J libs and log4j-core
, log4j-api
, aws-lambda-java-log4j2
and aws-lamda-java-core
are all in the package.
推荐答案
我也有这个问题。事实证明,AWS示例文档中存在拼写错误。
I also had this problem. It turns out that there is a typo bug in the AWS example documentation.
<$ c中的包
$ c>< Configuration .. 标签错误。
The packages
in the <Configuration ..
tag is wrong.
根据log4j 插件配置文档 packages
参数是一个包不是一个类。
According to the log4j plugin configuration docs the packages
parameter is a package not a class.
所以将你的log4j2.xml配置修改为......
So modify your log4j2.xml configuration to be...
<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.amazonaws.services.lambda.runtime.log4j2">
<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>
希望这会有所帮助。
干杯
Hope this helps. Cheers
这篇关于在aws lambda上使用Log4J2进行日志记录 - 找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!