Revert "Revert "Add structured logging on top of seelog"" #2797
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.
Summary
Logs in agent are very challenging to work with. This refactor aims to bring structured logs on top of seelong (for both, json and logfmt formats) for easier reading when debugging.
This PR only changes logs for task_manager.go as a PoC.
here's a sample of how the structured logs look like:
logfmt:
json:
Implementation details
The best course of action I found was to wrap seelog with a custom logger designed to just format the
message
part of seelog logger. The API had to change in order to add structured fields since seelog doesn't support those (it's possible through custom contexts, but this approach is too expensive and leaks file descriptors).To see how the new wrapper would be used, see task_manager.go in this PR.
Testing
New tests cover the changes:
Description for the changelog
A log in
logfmt
format that looked like this:level=info time=2020-11-17T23:37:53Z msg="Managed task [arn:aws:ecs:us-west-2:901447253822:task/ecs-exec-gamma/776f36ce708c4701b196779d125d5104]: Container [name=ecs-exec-alpine runtimeID=0d2799a853ebf2bd4bff7c2620c31d836ef457f31ff96fc9730e52633e536a35]: handling container change event [CREATED]" module=task_manager.go
Will now look like:
and for
json
format, it will change from:to:
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.