import { Injectable } from '@angular/core' ; import { AppConfig } from 'src/environments/environment' ; @ Injectable ( ) export class Log { public static Logger : Log = new Log ( ) ; static log ( ... args ) { Log . Logger . log ( ... args ) ; } static warn ( ... args ) { Log . Logger . warn ( ... args ) ; } static info ( ... args ) { Log . Logger . info ( ... args ) ; } static debug ( ... args ) { Log . Logger . debug ( ... args ) ; } static error ( error ) { Log . Logger . error ( error ) ; } constructor ( ) { } log ( ... args ) { this . consoleLog ( 'log' , ... args ) ; } warn ( ... args ) { this . consoleLog ( 'warn' , ... args ) ; } info ( ... args ) { this . consoleLog ( 'info' , ... args ) ; } debug ( ... args ) { this . consoleLog ( 'debug' , ... args ) ; } error ( ... args ) { this . consoleLog ( 'error' , ... args ) ; } private get logToConsole ( ) : boolean { return AppConfig . environment === 'LOCAL' && ! ! console ; } private consoleLog ( level , ... args ) { if ( this . logToConsole ) { this . getLogFunction ( level ) ( this . getLogPrefix ( ) , 'background: #444; color: #fff' , ... args ) ; } } private getDateStamp ( ) { return new Date ( ) . toLocaleString ( ) ; } private getLogPrefix ( ) { return `%c [${ this . getDateStamp ( ) }] Stratis Core:` ; } private getLogFunction ( level ) { return console [ level ] || console . log ; } }