Created
August 24, 2019 09:34
-
-
Save niraj-rai/dee875c4ab525853c5b78b1d1b5efce3 to your computer and use it in GitHub Desktop.
Logger Service and it's console logger implementation to handle logging strategy in dev and prod environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { environment } from '../../../environments/environment'; | |
export interface ILoggerService { | |
info(value: any, ...rest: any[]): void; | |
log(value: any, ...rest: any[]): void; | |
warn(value: any, ...rest: any[]): void; | |
error(value: any, ...rest: any[]): void; | |
} | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class ConsoleLoggerService implements ILoggerService { | |
info(value: any, ...rest: any[]): void { | |
if (!environment.production) | |
console.info(value, rest); | |
} | |
log(value: any, ...rest: any[]): void { | |
if (!environment.production) | |
console.log(value, rest); | |
} | |
warn(value: any, ...rest: any[]): void { | |
if (!environment.production) | |
console.warn(value, rest); | |
} | |
error(value: any, ...rest: any[]): void { | |
if (!environment.production) | |
console.error(value, rest); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment