import { Appender , LogLevel , LogRecord , LoggerFactory , LogMeta , Logger } from '@osd/logging' ; function isError ( x ) { return x instanceof Error ; } internal export class BaseLogger implements Logger { constructor ( private readonly context , private readonly level , private readonly appenders , private readonly factory ) { } public trace ( message , meta ? ) { this . log ( this . createLogRecord ( LogLevel . Trace , message , meta ) ) ; } public debug ( message , meta ? ) { this . log ( this . createLogRecord ( LogLevel . Debug , message , meta ) ) ; } public info ( message , meta ? ) { this . log ( this . createLogRecord ( LogLevel . Info , message , meta ) ) ; } public warn ( errorOrMessage , meta ? ) { this . log ( this . createLogRecord ( LogLevel . Warn , errorOrMessage , meta ) ) ; } public error ( errorOrMessage , meta ? ) { this . log ( this . createLogRecord ( LogLevel . Error , errorOrMessage , meta ) ) ; } public fatal ( errorOrMessage , meta ? ) { this . log ( this . createLogRecord ( LogLevel . Fatal , errorOrMessage , meta ) ) ; } public log ( record ) { if ( ! this . level . supports ( record . level ) ) { return ; } for ( const appender of this . appenders ) { appender . append ( record ) ; } } public get ( ... childContextPaths ) { return this . factory . get ( ... [ this . context , ... childContextPaths ] ) ; } private createLogRecord ( level , errorOrMessage , meta ? ) { if ( isError ( errorOrMessage ) ) { return { context : this . context , error : errorOrMessage , level , message : errorOrMessage . message , meta , timestamp : new Date ( ) , pid : process . pid , } ; } return { context : this . context , level , message : errorOrMessage , meta , timestamp : new Date ( ) , pid : process . pid , } ; } }