import * as log4javascript from "log4javascript" ; import { LogLevelConverter } from "./log-level.converter" ; import { LogLevel } from "./log-level.model" ; /**
 * Logger for writing log messages.
 */ export class Logger { private logger : log4javascript . Logger ; /**
     * Creates a new instance of a logger.
     */ constructor ( logger ? ) { if ( typeof logger === "undefined" ) { this . logger = log4javascript . getRootLogger ( ) ; } else if ( typeof logger === "string" ) { this . logger = log4javascript . getLogger ( logger ) ; } else { this . logger = logger ; } } /**
     * Get the log level.
     */ public getLogLevel ( ) { return LogLevelConverter . levelFromLog4Javascript ( this . logger . getLevel ( ) ) ; } param level public setLogLevel ( level ) { this . logger . setLevel ( LogLevelConverter . levelToLog4Javascript ( level ) ) ; } param methodName param params public trace ( methodName , ... params ) { if ( this . logger . isTraceEnabled ( ) ) { const args = [ methodName ] ; for ( const param of params ) { args . push ( this . formatArgument ( param ) ) ; } this . logger . trace . apply ( this . logger , args ) ; } } param methodName param params public debug ( methodName , ... params ) { if ( this . logger . isDebugEnabled ( ) ) { const args = [ methodName ] ; for ( const param of params ) { args . push ( this . formatArgument ( param ) ) ; } this . logger . debug . apply ( this . logger , args ) ; } } param methodName param params public info ( methodName , ... params ) { if ( this . logger . isInfoEnabled ( ) ) { const args = [ methodName ] ; for ( const param of params ) { args . push ( this . formatArgument ( param ) ) ; } this . logger . info . apply ( this . logger , args ) ; } } param methodName param params public warn ( methodName , ... params ) { if ( this . logger . isWarnEnabled ( ) ) { const args = [ methodName ] ; for ( const param of params ) { args . push ( this . formatArgument ( param ) ) ; } this . logger . warn . apply ( this . logger , args ) ; } } param methodName param params public error ( methodName , ... params ) { if ( this . logger . isErrorEnabled ( ) ) { const args = [ methodName ] ; for ( const param of params ) { args . push ( this . formatArgument ( param ) ) ; } this . logger . error . apply ( this . logger , args ) ; } } param methodName param params public fatal ( methodName , ... params ) { if ( this . logger . isFatalEnabled ( ) ) { const args = [ methodName ] ; for ( const param of params ) { args . push ( this . formatArgument ( param ) ) ; } this . logger . fatal . apply ( this . logger , args ) ; } } param methodName param params public entry ( methodName , ... params ) { if ( this . logger . isInfoEnabled ( ) ) { const args = [ methodName , "entry" ] ; if ( this . logger . isDebugEnabled ( ) ) { for ( const param of params ) { args . push ( this . formatArgument ( param ) ) ; } } this . logger . info . apply ( this . logger , args ) ; } } param methodName param params public exit ( methodName , ... params ) { if ( this . logger . isInfoEnabled ( ) ) { const args = [ methodName , "exit" ] ; if ( this . logger . isDebugEnabled ( ) ) { for ( const param of params ) { args . push ( this . formatArgument ( param ) ) ; } } this . logger . info . apply ( this . logger , args ) ; } } /**
     * Formats the given argument.
     */ public formatArgument ( arg ) { if ( typeof arg === "string" ) { return arg ; } else if ( typeof arg === "number" ) { return arg . toString ( ) ; } else if ( arg instanceof Error ) { return arg . toString ( ) ; } else { try { return JSON . stringify ( arg ) ; } catch ( e ) { return e . message ; } } } /**
     * Returns the internal Logger (for unit tests only).
     */ public getInternalLogger ( ) { return this . logger ; } }