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

Introduce SetCustomReceiver in the logger #4507

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

niyatim23
Copy link

@niyatim23 niyatim23 commented Feb 18, 2025

Summary

SetCustomReceiver configures the ECS Agent logger to use a custom logger implementation. This allows external applications to intercept and handle ECS Agent logs in their own way, such as sending logs to a custom destination or formatting them differently. More details can be found here
The custom receiver must implement the CustomReceiver interface, which requires:

  • GetTimestampFormat(): returns the desired timestamp format (e.g., "2006-01-02T15:04:05Z07:00")
  • GetOutputFormat(): returns the desired output format ("logfmt", "json", or "windows")
  • Log handling methods (Debug, Info, Warn, etc.)

Implementation details

  • Introduce a new public API SetCustomReceiver which accepts a customReceiver. This path is independent of the Config and creates its own custom config. It uses this config along with the receiver to create a replacement logger. The formatting of the message is still handled by seelog.
  • Introduce locks for timestampFormat to avoid race conditions while accessing it asynchronously

Testing

Tested via the unit tests to make sure that the logging functions in the receiver were triggered with the correct message

New tests cover the changes: Yes

Description for the changelog

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.

@niyatim23 niyatim23 force-pushed the dev branch 3 times, most recently from 450c096 to 7188395 Compare February 19, 2025 21:19
@niyatim23 niyatim23 changed the title Introduce SetCustomLogger from the logger Introduce SetCustomReceiver in the logger Feb 19, 2025
@niyatim23 niyatim23 marked this pull request as ready for review February 21, 2025 17:59
@niyatim23 niyatim23 requested a review from a team as a code owner February 21, 2025 17:59
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.

2 participants