我有一个用Java编写的AWS Lambda函数。我想使用自定义GraalVM运行时来运行Lambda函数,例如在this blog post中所做的那样
每当应用程序启动时,我都会收到以下错误:
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
我的log4j2.xml文件如下所示
<Configuration status="WARN">
<Appenders>
<Lambda name="Lambda">
<PatternLayout>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1} - %m%n</pattern>
</PatternLayout>
</Lambda>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Lambda"/>
</Root>
<Logger name="software.amazon.awssdk" level="WARN" />
<Logger name="software.amazon.awssdk.request" level="DEBUG" />
</Loggers>
</Configuration>
这里的其他类似问题表明这是由于fatjar中的log4j包冲突。基于this answer中的建议,我现在使用shadowJar和一个转换来构建GraalVM应用程序编译所用的fatjar。但是我仍然收到错误。
Gradle构建文件的相关部分如下所示
dependencies {
implementation platform('software.amazon.awssdk:bom:2.+')
implementation platform('com.amazonaws:aws-xray-recorder-sdk-bom:2.+')
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:2.2.9'
implementation 'com.amazonaws:aws-xray-recorder-sdk-core'
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-core'
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2'
implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2-instrumentor'
implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:2.13.2'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.formkiq:lambda-runtime-graalvm:1.1'
implementation project(":aws-java-utilities:utilities")
runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.2.0'
runtimeOnly 'mysql:mysql-connector-java:8.0.+'
// mqttv3 1.1.1 fails to connect for unknown reasons
testImplementation (group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.1.0'){force = true}
testImplementation 'com.amazonaws:aws-iot-device-sdk-java:1.3.+'
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
testImplementation "org.mockito:mockito-core:2.+"
testImplementation project(":aws-java-utilities:end2endTest-utilities")
testImplementation 'software.amazon.awssdk:rdsdata'
}
shadowJar {
archivesBaseName = project.name + '-lambda'
manifest {
attributes 'Main-Class': 'com.formkiq.lambda.runtime.graalvm.LambdaRuntime'
}
transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer)
}
如果我尝试运行jar(或者使用相同的任务但不同的主类进行构建),我会得到这个错误。
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
2021-01-16 19:35:23,290 main ERROR Error processing element Lambda ([Appenders: null]): CLASS_NOT_FOUND
2021-01-16 19:35:23,343 main ERROR Unable to locate appender "Lambda" for logger config "root"
我用来构建GraalVM应用程序的命令如下所示
docker run --rm -v $(pwd):/working oracle/graalvm-ce:20.1.0-java11 \
/bin/bash -c "
gu install native-image; \
native-image --enable-url-protocols=http,https \
-H:+AllowIncompleteClasspath \
-H:ReflectionConfigurationFiles=/working/src/main/resources/reflect.json \
-H:IncludeResourceBundles=com.mysql.cj.LocalizedErrorMessages \
-H:IncludeResources=.\*.properties \
-H:IncludeResources=.\*.xml \
-H:+ReportUnsupportedElementsAtRuntime -J-Xmx5G --no-server -jar \"/working/build/libs/$1-lambda-all.jar\";`
gradle dependencies
向我展示了所有对log4j的引用都使用了相同的版本,例如:
...
+--- org.apache.logging.log4j:log4j-slf4j18-impl:2.13.2
| +--- org.slf4j:slf4j-api:1.8.0-beta4
| +--- org.apache.logging.log4j:log4j-api:2.13.2
| \--- org.apache.logging.log4j:log4j-core:2.13.2
| \--- org.apache.logging.log4j:log4j-api:2.13.2
...
我看到一些关于这个主题的问题提到这是由于Log4j2Plugins.dat文件冲突。我可以在我的依赖项中看到我有两个这样的文件。一个在com.amazonaws:aws-lambda-java-log4j2:1.2.0
中,另一个在org.apache.logging.log4j:log4j-api:2.13.2
中。根据我之前链接的答案,我的gradle版本中的转换应该会处理这个问题,但我不知道如何验证这是否属实。
我一整天都在为这个问题绞尽脑汁,我真实的的不知道如何让伐木工作起来。
任何能让我前进的帮助都将不胜感激。
1条答案
按热度按时间j9per5c41#
我遇到了和你一样的问题。经过一番挖掘,我偶然发现了这个jira和github问题:
https://issues.apache.org/jira/browse/LOG4J2-2604
https://github.com/oracle/graal/issues/808
使用GraalVM构建时,您必须指定要捆绑的资源。应用github问题中指定的resource-config.json设置对我有效(但是,reflect-config.json不起作用)。
可以在另一个github问题www.example.com中找到工作反射配置https://github.com/oracle/graal/issues/2008#issuecomment-777858227