import bunyan = require ( 'bunyan' ) ; import { Request , Response , NextFunction } from 'express' ; import { User } from './../models/user' ; import CONFIG from './../config' ; const serializers = { user : ( user ) => User . toSafeUser ( user ) , req : ( req ) => { return { ip : req . ip , method : req . method , url : req . url } ; } } ; class Logger { private static req ? : Request ; private static bunyanLogger = bunyan . createLogger ( { name : 'budget' , streams : [ CONFIG . bunyanStream ] , serializers } ) ; static initialize ( ) { return ( req , res , next ) => { this . req = req ; next ( ) ; } ; } static info ( msg , fields ? ) { fields = { ... fields , req : this . req } ; this . bunyanLogger . info ( fields , msg ) ; } static warn ( msg , fields ? ) { fields = { ... fields , req : this . req } ; this . bunyanLogger . warn ( fields , msg ) ; } static error ( msg , fields ? ) { fields = { ... fields , req : this . req } ; this . bunyanLogger . error ( fields , msg ) ; } } export default Logger ;