-
Notifications
You must be signed in to change notification settings - Fork 152
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 Logging Incoming Event Without Use of Middy or Class #1904
Comments
Hi @bestickley , thanks for the feature request. This is indeed a missing feature for customer who are not using middy or decorator. I checked the implementation and from the first impression it looks like we could move event logging into the I think the tricky part is to keep the call clean as you did your example The feature request is valid and will bring value, we just need to agree on the implementation details. |
@am29d, I agree |
It's true that we have overloaded the meaning of the The overloading came also from a place of necessity. Both the Middy middleware and decorator wrap the handler and have access to its arguments (aka In this case the Starting from the assumption that you can already log the event by just calling If this is true I would be more inclined to go in a different direction:
|
I agree on having a separate method |
Hi both, while doing some maintenance on the Logger I noticed that we already have a mostly undocumented public method called The method would be used like this: import { Logger } from '@aws-lambda-powertools/logger';
const logger = new Logger();
export const handler = async (event: unknown) => {
logger.logEventIfEnabled(event); // (1)
// ... your handler code
}; It takes in account the value of For now I have opened a PR to add documentation and examples for this method and will be closing the issue once the PR is merged, since the first low hanging fruit has been addressed. In regards to a better and less verbose DX for users who don't want to use Middy.js nor class method decorators, we can continue the discussion in #1833. |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
This is now released under v2.9.0 version! |
Use case
I want the incoming log event to be automatically logged for me when
POWERTOOLS_LOGGER_LOG_EVENT
is set to true and I'm not using middy or a handler class. Middy and handler class usage is demonstrated in docs here.Solution/User Experience
Conditionally log incoming event based on
POWERTOOLS_LOGGER_LOG_EVENT
within Logger.addContext. I know this may seem strange to put "log incoming event logic" into theaddContext
method, but that's how it's implemented with middy (injectLambdaContext
) and class decorator (logger.injectLambdaContext
).With this solution, the below function would log incoming event. Currently it does not.
Alternative solutions
No response
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: