import { Inject , Injectable , InjectionToken , Optional } from '@angular/core' ; import { LogLevel } from '../constants' ; export const LOGLEVEL = new InjectionToken < LogLevel > ( 'LogLevel' ) ; @ Injectable ( { providedIn : 'root' } ) export class LoggerService { constructor ( @ Inject ( LOGLEVEL ) @ Optional ( ) protected _logLevel ) { if ( this . _logLevel === null || this . _logLevel === undefined ) { this . _logLevel = LogLevel . Warning ; } } protected logWith ( logFunc , logLevel , message ? , ... optionalParams ) { if ( logLevel >= this . _logLevel ) { try { logFunc ( message , ... optionalParams ) ; } catch { } } } logTrace ( message ? , ... optionalParams ) { this . logWith ( console . log , LogLevel . Trace , message , ... optionalParams ) ; } logDebug ( message ? , ... optionalParams ) { this . logWith ( console . log , LogLevel . Debug , message , ... optionalParams ) ; } logInfo ( message ? , ... optionalParams ) { this . logWith ( console . log , LogLevel . Info , message , ... optionalParams ) ; } logWarning ( message ? , ... optionalParams ) { this . logWith ( console . warn , LogLevel . Warning , message , ... optionalParams ) ; } logError ( message ? , ... optionalParams ) { this . logWith ( console . error , LogLevel . Error , message , ... optionalParams ) ; } }