Skip to content

Intended best practices to avoid cross-cutting concerns #1199

Answered by dreamorosi
codyfrisch asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @codyfrisch, thank you for starting this discussion!

I understand that you'd like to reuse the same instance of logger throughout your different classes/functions, and ideally this instance should have already been injected with the context.

A pattern that we recommend would be to have your logger object instantiated in a shared file that can be imported throughout your codebase:

For instance, have a file called powertools.ts:

import { Logger } from '@aws-lambda-powertools/logger';

export const logger = new Logger();

Then, in your main index.ts file, have your class:

import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
import { logger } from './common/pow…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@codyfrisch
Comment options

Answer selected by codyfrisch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants