/**
 * Refinement of `console` interface only for important information i.e `info`, `warn` and `errors`.
 */ export interface ISimpleChannel { info ( message ? , ... optionalParams ) : void ; warn ( message ? , ... optionalParams ) : void ; error ( message ? , ... optionalParams ) : void ; } /**
 * Extension of  ISimpleChannel to support contextual logging by adding stack of prefixes.
  export interface IContextLogger extends ISimpleChannel { /**
     * Push "attribute-like" context.
     */ pushAttr ( name ) : void ; /**
     * Push "index-like" context.
     *
     * Following log messages will be prefixed with `[index]`.
     */ pushIndex ( index ) : void ; /**
     * Remove current context from top of stack.
     */ pop ( ) : void ; } /**
 * Context-aware logger that decorates log message with stack-based prefix, emits `headerMessage`
 * before first actual log message.
 */ export class ContextLogger implements IContextLogger { private readonly context : string [ ] = [ ] ; private m_headerLogged = false ; /**
     * Construct a context-aware logger that logs to `m_logger`.
     */ constructor ( readonly m_logger , readonly headerMessage ) { } /**
     * Push "attribute-like" context.
     *
     * Following log messages will be prefixed with `name` or `.name` depending on current context.
     */ pushAttr ( name ) { this . context . push ( `${ this . context . length > 0 ? "." : "" }${ name }` ) ; } /**
     * Push "index-like" context.
     *
     * Following log messages will be prefixed with `[index]`.
     */ pushIndex ( index ) { this . context . push ( `[${ index }]` ) ; } pop ( ) { this . context . pop ( ) ; } warn = this . createLogMethod ( "warn" ) ; info = this . createLogMethod ( "info" ) ; error = this . createLogMethod ( "error" ) ; private createLogMethod ( severity ) { return ( message , ... rest ) => { if ( ! this . m_headerLogged ) { this . m_logger . info ( this . headerMessage ) ; this . m_headerLogged = true ; } this . m_logger [ severity ] ( `${ this . context . join ( "" ) }: ${ message }` , ... rest ) ; } ; } }