Skip to content

Feature request: Support Logging Incoming Event Without Use of Middy or Class #1904

Closed
@bestickley

Description

@bestickley

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 the addContext 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.

import { Logger } from "@aws-lambda-powertools/logger";
process.env.POWERTOOLS_LOGGER_LOG_EVENT = "true";
const logger = new Logger();
export function handler(event, context) {
  logger.addContext(context);
  // do work
}

Alternative solutions

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedfeature-requestThis item refers to a feature request for an existing or new utilityloggerThis item relates to the Logger Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions