Skip to content

Conversation

@pankajagrawal16
Copy link
Contributor

Closes #31

This test if the logs printed via log4j config xml is structured as well has correct keys injected from lambda context

<Configuration packages="com.amazonaws.services.lambda.runtime.log4j2">
<Appenders>
<Console name="JsonAppender" target="SYSTEM_OUT">
<File name="JsonAppender" fileName="target/logfile.json">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change make log4j to log to a file which we have used in our regression test to make sure the structured logging works correctly with correct lambda keys injected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, it is not the default appender? Why not creating two log4j config file to test both?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so difficult to test system out. I think this is a very slick way of testing the functionality.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok good point

initMocks(this);
setupContext();
//Make sure file is cleaned up before running full stack logging regression
FileChannel.open(Paths.get("target/logfile.json"), StandardOpenOption.WRITE).truncate(0).close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


assertThat(Files.lines(Paths.get("target/logfile.json")))
.hasSize(1)
.allSatisfy(line -> assertThat(parseToMap(line))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v cool.

@pankajagrawal16 pankajagrawal16 merged commit 290e87c into master Aug 19, 2020
@pankajagrawal16 pankajagrawal16 deleted the regression-full-stack-log branch August 19, 2020 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression tests on log4j logging for LambdaJsonLayout

3 participants