Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register custom logger before it gets used #2438

Merged
merged 1 commit into from
Apr 29, 2020
Merged

Register custom logger before it gets used #2438

merged 1 commit into from
Apr 29, 2020

Conversation

shubham2892
Copy link
Contributor

Summary

When ECS_LOGLEVEL is set in Agent config file, healthcheck outputs shows following error -- [Error] format error: unrecognized formatter at 1: EcsAgentLogfmt\n"

It's because when ECS_LOGLEVEL is set, logger tries to load EcsAgentLogFmt custom formatter before it is initiated.
EcsAgentLogFmt gets loaded here -- https://github.com/aws/amazon-ecs-agent/blob/master/agent/logger/log.go#L97 which is being called by SetLevel() here -- https://github.com/aws/amazon-ecs-agent/blob/master/agent/logger/log.go#L97.

Currently custom formatter is initiated here -- https://github.com/aws/amazon-ecs-agent/blob/master/agent/logger/log.go#L167

Moving the initiation of custom formatter before SetLevel ensure that the formatter is initiated before it is getting loaded.

Implementation details

Testing

Steps to reproduce the issue --

  1. Set ECS_LOGLEVEL=debug in /etc/ecs/ecs.config on al2.
  2. Restart agent
  3. docker inspect <agent container id>. Health check shows error format error: unrecognized formatter at 1: EcsAgentLogfmt\n

After the change, the health check was passing with ECS_LOGLEVEL set and I could see logs getting generated as expected in Agent log directory.

Description for the changelog

Bug - Health check output shows error message when ECS_LOGLEVEL is set in Agent config file.

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@shubham2892 shubham2892 requested a review from a team April 23, 2020 22:03
@petderek
Copy link
Contributor

You should fix your commit. The author is root.

Copy link
Contributor

@petderek petderek left a comment

Choose a reason for hiding this comment

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

Cool fix, though!

@shubham2892 shubham2892 changed the title Register custom logger wbefore it gets used Register custom logger before it gets used Apr 24, 2020
@shubham2892 shubham2892 merged commit c35989e into aws:dev Apr 29, 2020
@shubham2892 shubham2892 deleted the log-fix branch April 29, 2020 17:21
@shubham2892 shubham2892 added this to the 1.40.0 milestone May 5, 2020
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.

5 participants