import { Inject , Provider } from '@nestjs/common' ; import { PinoLogger } from './PinoLogger' ; const decoratedTokenPrefix = 'PinoLogger:' ; const decoratedLoggers = new Set < string > ( ) ; export function InjectPinoLogger ( context = '' ) { decoratedLoggers . add ( context ) ; return Inject ( getLoggerToken ( context ) ) ; } function createDecoratedLoggerProvider ( context ) { return { provide : getLoggerToken ( context ) , useFactory : ( logger ) => { logger . setContext ( context ) ; return logger ; } , inject : [ PinoLogger ] , } ; } export function createProvidersForDecorated ( ) { return [ ... decoratedLoggers . values ( ) ] . map ( createDecoratedLoggerProvider ) ; } export function getLoggerToken ( context ) { return `${ decoratedTokenPrefix }${ context }` ; }