import { Request , Response } from 'express' ; import { injectable } from 'inversify' ; import ILogger from '../interfaces/ilogger' ; const pino = require ( 'pino' ) ( ) ; /**
 * Logging Facade that wraps the Pino logger implementation
 */ @ injectable ( ) class LogService implements ILogger { private logger : any ; private uuid : string ; public constructor ( ) { this . initLogger ( ) ; } public getLogger ( ) { return this . logger ; } public info ( ... message ) { const UUID = this . getUUID ( ) ; this . logger . info ( { UUID , data : { ... message } } ) ; } public debug ( ... message ) { const UUID = this . getUUID ( ) ; this . logger . debug ( { UUID , data : { ... message } } ) ; } public error ( ... message ) { const UUID = this . getUUID ( ) ; this . logger . error ( { UUID , data : { ... message } } ) ; } param req param res param message public logAPITraceOut ( req , res , message ? ) { const fullUrl = req . protocol + '://' + req . get ( 'host' ) + req . originalUrl ; const responseTime = res . getHeader ( 'x-response-time' ) ; const status = res . status ; const uuid = this . getUUID ( ) ; if ( message !== undefined ) { this . logger . info ( { uuid , fullUrl , status , responseTime , message } ) ; } else { this . logger . info ( { uuid , fullUrl , status , responseTime } ) ; } } public logAPITrace ( req , res , statusCode , message ? ) { const fullUrl = req . protocol + '://' + req . get ( 'host' ) + req . originalUrl ; const responseTime = res . getHeader ( 'x-response-time' ) ; const uuid = this . getUUID ( ) ; if ( message !== undefined ) { this . logger . info ( { uuid , fullUrl , statusCode , responseTime , message } ) ; } else { this . logger . info ( { uuid , fullUrl , statusCode , responseTime } ) ; } } public setUUID ( uuid ) { this . uuid = uuid ; } public getUUID ( ) { return this . uuid ; } private initLogger ( ) { this . logger = pino ; } } export default LogService ;