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

Feature request: Support of the assert of the Logging.Log buffer when testing #426

Open
2 tasks done
coderade opened this issue Sep 5, 2023 · 2 comments
Open
2 tasks done
Assignees
Labels
area/logging Core logging utility feature-request New or enhancements to existing features
Milestone

Comments

@coderade
Copy link

coderade commented Sep 5, 2023

Use case

When creating Unit Tests, I want to be able to assert if the messages have been logged on the AWS.Lambda.Powertools.Logging.Logger instance buffer.

This will be helpful to assert in the tests the logged messages for the current logger instance, like is possible with the Amazon.Lambda.TestUtilities.

Is it already possible in some way? And/Or does this feature request make sense?

Solution/User Experience

Currently the Amazon.Lambda.TestUtilities provides the TestLambdaLogger() implementation of the ILambdaLogger that stores all the messages in a buffer and writes the messages to the console.

With this helper we can assert if the message has been logged:

var logger = new TestLambdaLogger();
Assert.Contains("Processed message foobar", logger.Buffer.ToString());

Creating this kind of helper can be a good way to follow for the AWS.Lambda.Powertools.Logging.Logger or creating a method to get the current logger instance.

Alternative solutions

No response

Acknowledgment

@coderade coderade added feature-request New or enhancements to existing features triage Pending triage from maintainers labels Sep 5, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 5, 2023

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #dotnet channel on our Powertools for AWS Lambda Discord: Invite link

@hjgraca hjgraca added the area/logging Core logging utility label Sep 11, 2023
@hjgraca
Copy link
Contributor

hjgraca commented Sep 13, 2023

Thanks for opening the issue @coderade we are experimenting with different approaches:
A couple of questions:

  1. How are you logging, can you share a snippet?
  2. Are you using a static Logger, creating a logging instance in the constructor or other?
  3. Are you using ILambdaContext outside the handler?

We are thinking of one approach, if in a Lambda environment (were we have access to context) we will write to the context.Log output so you will have the message in the TestLambdaLogger buffer and you can assert on that.

@hjgraca hjgraca self-assigned this Sep 21, 2023
@hjgraca hjgraca removed the triage Pending triage from maintainers label Sep 21, 2023
@hjgraca hjgraca moved this from 🆕 New to 🏗 In progress in Powertools for AWS Lambda (.NET) Sep 21, 2023
@hjgraca hjgraca added this to the Logging V2 milestone Dec 12, 2023
@hjgraca hjgraca moved this from 🏗 In progress to 📋 Backlog in Powertools for AWS Lambda (.NET) Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Core logging utility feature-request New or enhancements to existing features
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants