import * as winston from 'winston' ; import config from './config' ; winston . configure ( { level : config . logging . level , transports : [ newConsoleTransport ( ) ] } ) ; param name export function newConsoleTransport ( name ? ) { return new ( winston . transports . Console ) ( { label : name || '' , timestamp : true , json : config . logging . format === 'json' , colorize : config . logging . colorize , prettyPrint : config . logging . format === 'text' , showLevel : true } ) ; } const EXCEPTION_CAPTION = 'Throwed exception: ' ; /**
 * Simple logger with tags.
 */ declare interface SubLogger { addPrefix ( text ) : SubLogger ; addMeta ( meta ) : SubLogger ; debug ( msg , ... meta ) ; verbose ( msg , ... meta ) ; info ( msg , ... meta ) ; warn ( msg , ... meta ) ; error ( msg , ... meta ) ; exception ( ... meta ) ; } /**
 * Logger
 */ export class Logger extends winston . Logger { private static loggers : any = { } ; private constructor ( private name ) { super ( { level : config . logging . level , transports : [ newConsoleTransport ( name ) ] } ) ; } param name static getInstance ( name ) { name = name || '' ; if ( this . loggers [ name ] ) { return this . loggers [ name ] ; } return this . loggers [ name ] = new Logger ( name ) ; } param initialMeta sub ( initialMeta , initialPrefix ? ) { let meta = initialMeta ? { meta : { ... initialMeta } } : { } ; let prefix = initialPrefix || '' ; return { addPrefix : ( text ) : SubLogger => { return this . sub ( meta . meta , prefix + text ) ; } , addMeta : ( assignMeta ) : SubLogger => { return this . sub ( { ... assignMeta , ... meta . meta } , prefix ) ; } , debug : ( msg , ... customMeta ) => { return this . debug ( prefix + msg , ... customMeta , meta ) ; } , verbose : ( msg , ... customMeta ) => { return this . verbose ( prefix + msg , ... customMeta , meta ) ; } , info : ( msg , ... customMeta ) => { return this . info ( prefix + msg , ... customMeta , meta ) ; } , warn : ( msg , ... customMeta ) => { return this . warn ( prefix + msg , ... customMeta , meta ) ; } , error : ( msg , ... customMeta ) => { return this . error ( prefix + msg , ... customMeta , meta ) ; } , exception : ( ... customMeta ) => { return this . error ( prefix + EXCEPTION_CAPTION , ... customMeta , meta ) ; } } ; } exception ( msg , ... meta ) { return this . error ( EXCEPTION_CAPTION + msg , ... meta ) ; } }