Created
April 4, 2017 13:50
-
-
Save merlosy/8c13c22d1d2a939e1cde160496a30b51 to your computer and use it in GitHub Desktop.
safe logger in Typescript
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 { environment } from './../../../environments/environment'; | |
export class Logger { | |
public static isActive = () => !environment.production; | |
private static noop = function(){}; | |
public static info = Logger.isActive()? ( console && console.info ) && console.info.bind(console) : Logger.noop; | |
public static log = Logger.isActive()? ( console && console.log ) && console.log.bind(console) : Logger.noop; | |
public static debug = Logger.isActive()? ( console && console.debug ) && console.debug.bind(console) : Logger.noop; | |
public static warn = Logger.isActive()? ( console && console.warn ) && console.warn.bind(console) : Logger.noop; | |
public static error = Logger.isActive()? ( console && console.error ) && console.error.bind(console) : Logger.noop; | |
public static assert = Logger.isActive()? ( console && console.assert ) && console.assert.bind(console) : Logger.noop; | |
public static trace = Logger.isActive()? ( console && console.trace ) && console.trace.bind(console) : Logger.noop; | |
public static time = Logger.isActive()? ( console && console.time ) && console.time.bind(console) : Logger.noop; | |
public static timeEnd = Logger.isActive()? ( console && console.timeEnd ) && console.timeEnd.bind(console) : Logger.noop; | |
public static group = Logger.isActive()? ( console && console.group ) && console.group.bind(console) : Logger.noop; | |
public static groupEnd = Logger.isActive()? ( console && console.groupEnd ) && console.groupEnd.bind(console) : Logger.noop; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment