import { ConsoleLogger } from "./ConsoleLogger" ; import { ILogger } from "./ILogger" ; category export class LogLevel { /**
     * The TRACE channel
     */ public static readonly TRACE = new LogLevel ( "TRACE" , - 1 ) ; /**
     * The DEBUG channel
     */ public static readonly DEBUG = new LogLevel ( "DEBUG" , 0 ) ; /**
     * The INFO channel
     */ public static readonly INFO = new LogLevel ( "INFO" , 1 ) ; /**
     * The WARN channel
     */ public static readonly WARN = new LogLevel ( "WARN" , 2 ) ; /**
     * The ERROR channel
     */ public static readonly ERROR = new LogLevel ( "ERROR" , 3 ) ; private constructor ( private level , private sequence ) { } public includes ( level ) { return level . sequence >= this . sequence ; } public toString ( ) { return this . level ; } public static fromString ( level , defaultLevel = LogLevel . DEBUG ) { if ( ! level ) return defaultLevel ; if ( level . toUpperCase ( ) === LogLevel . TRACE . level ) return LogLevel . TRACE ; if ( level . toUpperCase ( ) === LogLevel . DEBUG . level ) return LogLevel . DEBUG ; if ( level . toUpperCase ( ) === LogLevel . INFO . level ) return LogLevel . INFO ; if ( level . toUpperCase ( ) === LogLevel . WARN . level ) return LogLevel . WARN ; if ( level . toUpperCase ( ) === LogLevel . ERROR . level ) return LogLevel . ERROR ; return defaultLevel ; } } category export class LogService { private static logger : ILogger = new ConsoleLogger ( ) ; private static logLevel : LogLevel = LogLevel . INFO ; private static mutedModules : string [ ] = [ ] ; private constructor ( ) { } /**
     * The level at which the LogService is running.
     */ public static get level ( ) : LogLevel { return this . logLevel ; } param { LogLevel } level public static setLevel ( level ) { LogService . logLevel = level || LogLevel . DEBUG ; } param { ILogger } logger public static setLogger ( logger ) { LogService . logger = logger ; } param { string } name public static muteModule ( name ) { LogService . mutedModules . push ( name ) ; } param { string } module param { any [ ] } messageOrObject public static trace ( module , ... messageOrObject ) { if ( ! LogService . logLevel . includes ( LogLevel . TRACE ) ) return ; if ( LogService . mutedModules . includes ( module ) ) return ; LogService . logger . trace ( module , ... messageOrObject ) ; } param { string } module param { any [ ] } messageOrObject public static debug ( module , ... messageOrObject ) { if ( ! LogService . logLevel . includes ( LogLevel . DEBUG ) ) return ; if ( LogService . mutedModules . includes ( module ) ) return ; LogService . logger . debug ( module , ... messageOrObject ) ; } param { string } module param { any [ ] } messageOrObject public static error ( module , ... messageOrObject ) { if ( ! LogService . logLevel . includes ( LogLevel . ERROR ) ) return ; if ( LogService . mutedModules . includes ( module ) ) return ; LogService . logger . error ( module , ... messageOrObject ) ; } param { string } module param { any [ ] } messageOrObject public static info ( module , ... messageOrObject ) { if ( ! LogService . logLevel . includes ( LogLevel . INFO ) ) return ; if ( LogService . mutedModules . includes ( module ) ) return ; LogService . logger . info ( module , ... messageOrObject ) ; } param { string } module param { any [ ] } messageOrObject public static warn ( module , ... messageOrObject ) { if ( ! LogService . logLevel . includes ( LogLevel . WARN ) ) return ; if ( LogService . mutedModules . includes ( module ) ) return ; LogService . logger . warn ( module , ... messageOrObject ) ; } } param { Error } err returns { * } category export function extractRequestError ( err ) { if ( err ?. [ 'body' ] ) { return err [ 'body' ] ; } return err ; }