fix(logger): buffer logs emitted during init #2277
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR updates the initialization logic of the Logger utility so that any log emitted during this phase is buffered until the Logger has been fully initialized.
As part of the utility initialization we need to perform a number of actions to configure the content of the logs, their format, and the general behavior of the utility.
Some of these setup actions can emit warnings or debug logs if certain conditions are met. One of these is when the customer initializes the Logger with a log level that is more verbose than the one set in the Lambda ALC.
For those setup steps that require logging it was important that things like the log formatter were already configured, otherwise the operation would fail as reported in #2269.
Rather than simply swapping the order of the steps to fix the issue in the linked issue, this PR removes this type of dependency by introducing a rudimentary log buffer that will store any log emitted during the init phase. These logs are buffered until the initialization is complete and then are emitted.
In order to support this feature I had to do some minor refactor to ensure that the logs are emitted using the correct timestamp - aka the one at which they were emitted and not the one at which the buffer is flushed.
While there I also took the opportunity to simplify and document the logic of the method that initializes the log item.
Finally, I also took the liberty to refactor a test fixture that was extremely verbose and hard to understand as well as add new test cases to ensure that the logs are buffered and emitted correctly.
Related issues, RFCs
Issue number: #2269
Checklist
Breaking change checklist
Is it a breaking change?: NO
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.