Skip to content

chore: Add automatic registration of standard logging services and ILogger #938

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 5 commits into from
Jul 22, 2025

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Jul 21, 2025

Please provide the issue number

Issue number: #937

Summary

Changes

This pull request enhances the AddPowertoolsLogger method in AWS.Lambda.Powertools.Logging to improve service registration and logging functionality. The most notable changes include adding standard logging services and automatically registering the ILogger interface.

Improvements to service registration:

Enhancements to logging functionality:

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@boring-cyborg boring-cyborg bot added the area/logging Core logging utility label Jul 21, 2025
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 21, 2025
@hjgraca hjgraca linked an issue Jul 21, 2025 that may be closed by this pull request
@github-actions github-actions bot added the internal Maintenance changes label Jul 21, 2025
Copy link

codecov bot commented Jul 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.38%. Comparing base (3cd704a) to head (cf5f8bd).
Report is 6 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #938      +/-   ##
===========================================
+ Coverage    77.31%   77.38%   +0.06%     
===========================================
  Files          271      271              
  Lines        10864    10870       +6     
  Branches      1280     1281       +1     
===========================================
+ Hits          8400     8412      +12     
+ Misses        2046     2041       -5     
+ Partials       418      417       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@j-d-ha
Copy link

j-d-ha commented Jul 21, 2025

Hi @hjgraca! I tried adding the temporary fix you mentioned here and it had a weird side effect. It looks like log messages are being output twice, once as a standard log message and once as a structured log message (as expected):
image

For this PR, I think the logging provider that you added on 86 might need to be removed later to avoid this issue.

It's also possible that the temp fix I tried works differently and as such, this is a non-issue 😄.

@hjgraca
Copy link
Contributor Author

hjgraca commented Jul 21, 2025

Hi @hjgraca! I tried adding the temporary fix you mentioned here and it had a weird side effect. It looks like log messages are being output twice, once as a standard log message and once as a structured log message (as expected): image

For this PR, I think the logging provider that you added on 86 might need to be removed later to avoid this issue.

It's also possible that the temp fix I tried works differently and as such, this is a non-issue 😄.

Ah yes, it needs to clear providers, good catch

builder.Logging.ClearProviders();

@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 21, 2025
@boring-cyborg boring-cyborg bot added the tests label Jul 21, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jul 21, 2025
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 21, 2025
@hjgraca
Copy link
Contributor Author

hjgraca commented Jul 21, 2025

To prevent multiple logger providers the user can do it manually

builder.Logging.ClearProviders();

or with the new method override ClearExistingProviders

    builder.Logging.AddPowertoolsLogger(config =>
        {
        config.Service = "TestService";
        config.LoggerOutputCase = LoggerOutputCase.PascalCase;
        }, clearExistingProviders: true);

@j-d-ha
Copy link

j-d-ha commented Jul 21, 2025

To prevent multiple logger providers the user can do it manually

builder.Logging.ClearProviders();

or with the new method override ClearExistingProviders

    builder.Logging.AddPowertoolsLogger(config =>
        {
        config.Service = "TestService";
        config.LoggerOutputCase = LoggerOutputCase.PascalCase;
        }, clearExistingProviders: true);

I ran a test with this, and it works. Thank you!

@hjgraca hjgraca requested a review from leandrodamascena July 22, 2025 09:04
Copy link

@hjgraca hjgraca merged commit 6d45601 into develop Jul 22, 2025
9 checks passed
@hjgraca hjgraca deleted the fix/logging-auto-dependency-addpowertoolslogger branch July 22, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Core logging utility documentation Improvements or additions to documentation internal Maintenance changes size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: AddPowertoolsLogger does not add logger to DI Container
3 participants