license import { Injectable } from '@angular/core' ; export const enum ConsoleLogType { Debug = 'debug' , Log = 'log' , Info = 'info' , Warn = 'warn' , Error = 'error' } const nativeConsole = { debug : console . debug , log : console . log , info : console . info , warn : console . warn , error : console . error , } ; export interface ConsoleLogEvent { type : ConsoleLogType ; args : any [ ] ; } @ Injectable ( { providedIn : 'root' , } ) export class ConsoleOverwiteService { nativeConsole = nativeConsole ; setLogListener ( fn ) { this . overwriteLogFn ( ConsoleLogType . Debug , fn ) ; this . overwriteLogFn ( ConsoleLogType . Log , fn ) ; this . overwriteLogFn ( ConsoleLogType . Info , fn ) ; this . overwriteLogFn ( ConsoleLogType . Warn , fn ) ; this . overwriteLogFn ( ConsoleLogType . Error , fn ) ; } private overwriteLogFn ( type , listener ) { console [ type ] = ( ... args ) => { listener ( { type , args , } ) ; nativeConsole [ type ] . apply ( console , args ) ; } ; } }