You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.0 KiB
TypeScript
58 lines
1.0 KiB
TypeScript
/* eslint-disable no-console */
|
|
import { Injectable } from '@angular/core';
|
|
import { environment } from '../../../environments/environment';
|
|
export const { isDebugMode } = environment;
|
|
const noop = (): any => null;
|
|
|
|
export abstract class Logger {
|
|
|
|
info: any;
|
|
warn: any;
|
|
error: any;
|
|
|
|
}
|
|
|
|
@Injectable()
|
|
export class LoggerService implements Logger {
|
|
|
|
info: any;
|
|
warn: any;
|
|
error: any;
|
|
invokeConsoleMethod(type: string, args?: any): void { }
|
|
|
|
}
|
|
|
|
@Injectable()
|
|
export class ConsoleLoggerService implements Logger {
|
|
|
|
get info() {
|
|
if (isDebugMode) {
|
|
return console.log.bind(console);
|
|
} else {
|
|
return noop;
|
|
}
|
|
}
|
|
|
|
get warn() {
|
|
if (isDebugMode) {
|
|
return console.warn.bind(console);
|
|
} else {
|
|
return noop;
|
|
}
|
|
}
|
|
|
|
get error() {
|
|
if (isDebugMode) {
|
|
return console.error.bind(console);
|
|
} else {
|
|
return noop;
|
|
}
|
|
}
|
|
|
|
invokeConsoleMethod(type: string, args?: any): void {
|
|
const logFn: Function = (console)[type] || console.log || noop;
|
|
logFn.apply(console, [args]);
|
|
}
|
|
|
|
}
|