import { ConsoleLogger , Injectable } from '@nestjs/common' ; import { PinoLogger } from 'nestjs-pino' ; @ Injectable ( ) export class PinoLoggerService extends ConsoleLogger { readonly contextName : string ; constructor ( readonly logger ) { super ( ) ; this . contextName = 'context' ; } setContext ( name ) { this . logger . setContext ( name ) ; } verbose ( message , context ? , ... args ) { if ( context ) { this . logger . trace ( { [ this . contextName ] : context } , message , ... args ) ; } else { this . logger . trace ( message , ... args ) ; } } debug ( message , context ? , ... args ) { if ( context ) { this . logger . debug ( { [ this . contextName ] : context } , message , ... args ) ; } else { this . logger . debug ( message , ... args ) ; } } log ( message , context ? , ... args ) { if ( context ) { this . logger . info ( { [ this . contextName ] : context } , message , ... args ) ; } else { this . logger . info ( message , ... args ) ; } } warn ( message , context ? , ... args ) { if ( context ) { this . logger . warn ( { [ this . contextName ] : context } , message , ... args ) ; } else { this . logger . warn ( message , ... args ) ; } } error ( message , trace ? , context ? , ... args ) { if ( context ) { this . logger . error ( { [ this . contextName ] : context , trace } , message , ... args ) ; } else if ( trace ) { this . logger . error ( { trace } , message , ... args ) ; } else { this . logger . error ( message , ... args ) ; } } }