Skip to content

Register seelog log formatter before using it #4718

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

Merged
merged 1 commit into from
Jul 18, 2025
Merged

Conversation

amogh09
Copy link
Contributor

@amogh09 amogh09 commented Jul 18, 2025

Summary

The ECS init service was encountering a "format error: unrecognized formatter at 1: InitLogfmt" error during startup. This occurred because the custom formatter InitLogfmt was being used in the seelog configuration before it was registered with the seelog library. This fixes #4680.

Root Cause Analysis

The issue was in the initialization sequence in the Setup() function in logger/log.go:

  1. The function first checked for a log level environment variable and called SetLogLevel()
  2. SetLogLevel() internally called reloadConfig(), which tried to use the InitLogfmt formatter
  3. Only after this did the code register the formatter with seelog.RegisterCustomFormatter()
  4. This timing issue caused the error message to appear during startup

Implementation details

Reordered the initialization sequence in the Setup() function to:

  1. Register the custom formatter first, before any logging configuration is loaded
  2. Then set the log level from the environment variable if provided
  3. If no log level is set, reload the configuration to apply the formatter registration

This ensures that the formatter is registered before any attempt to use it in the logging configuration.

Testing

The fix was tested by:

  1. Compiling a new binary with the changes
  2. Replacing the existing binary on a running system
  3. Verifying that the service starts without the error message
  4. Confirming that logging works properly in both the journal and log files

New tests cover the changes: no

Description for the changelog

Fixed "unrecognized formatter" error by registering custom log formatter before loading seelog configuration.

Additional Information

Does this PR include breaking model changes? If so, Have you added transformation functions?

No

Does this PR include the addition of new environment variables in the README?

No

Licensing

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

@amogh09 amogh09 marked this pull request as ready for review July 18, 2025 21:26
@amogh09 amogh09 requested a review from a team as a code owner July 18, 2025 21:26
@amogh09 amogh09 merged commit 1c1c86d into aws:dev Jul 18, 2025
40 checks passed
timj-hh pushed a commit to timj-hh/amazon-ecs-agent that referenced this pull request Jul 19, 2025
@danehlim danehlim mentioned this pull request Jul 23, 2025
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.

4 participants