Skip to content

Instantly share code, notes, and snippets.

@niraj-rai
Created August 24, 2019 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save niraj-rai/dee875c4ab525853c5b78b1d1b5efce3 to your computer and use it in GitHub Desktop.
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.
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