Log4j2 Incompatibility with SAM
Hi Guys,
I'm facing very strange issue that when I'm adding log4j2 configuration my functions stops to work correctly.
I have a project that contains dependencies to https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-log4j2 and when everything is done according to instructions My functions stops to work correctly and returns:
Function returned an invalid response (must include one of: body, headers or statusCode in the response object): invalid character '-' after top-level
When I copy log4j2.xml to src/main/resources in maven function works fine but as expected log4j2 configuration can't be found
START RequestId: aa632e55-8cd9-4b7e-9d3f-196cdab74f9e Version: $LATEST Save started...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.
..... End everything is green.
After playing with this issue it looks like that even simple sysout with text breaks overal execution and Error is returned: Function returned an invalid response (must include one of: body, headers or statusCode in the response object): invalid character '-' after top-level
It looks like if I put simple sysout in any place of code that will be executed AWS Sam will crash.
e.g.: Such function works fine:
public class Function implements RequestStreamHandler { @Override public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException
//My Code }}
And such code crashes:
public class Function implements RequestStreamHandler { @Override public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException System.out.println("Hi"); //My Code }}
I'm having the same problem. Log4j2 works fine when deployed to AWS but fails when I try to run the lambda using sam local.
This should work in latest version of SAM CLI v0.3.0. Can you check and re-open if it doesn't?