Created
May 7, 2016 23:06
-
-
Save abcarroll/1d1d4b33c5fa4f76a95657c423c1ebd1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Emulates a PHP PSR-3-like interface. | |
* | |
* @type {{emergency: $log.emergency, alert: $log.alert, critical: $log.critical, error: $log.error, warning: $log.warning, notice: $log.notice, info: $log.info, debug: $log.debug, log: $log.log}} | |
*/ | |
var Logger = function () { | |
this.logger = {}; | |
var psrToConsole = { | |
'emergency': 'error', | |
'alert': 'error', | |
'critical': 'error', | |
'error': 'error', | |
'warning': 'warn', | |
'notice': 'info', | |
'info': 'info', | |
'debug': 'log', | |
'log': 'log', | |
// non-psr | |
'dump': 'dir', | |
'trace': 'trace' | |
}; | |
var t; | |
for (var m in psrToConsole) { | |
if (psrToConsole.hasOwnProperty(m)) { | |
t = psrToConsole[m]; | |
if (typeof console[t] == 'function') { | |
this.logger[m] = console[t].bind(window.console); | |
} | |
} | |
} | |
return this.logger | |
}; | |
$log = new Logger(); | |
/** | |
* Tricks IDEs like WebStorm into showing a cross-out through 'console' | |
*/ | |
var $trickIde$neverDefined$; | |
if (typeof $trickIde$neverDefined$ === true) { | |
/** | |
* @name console | |
* @Xdeprecated Use $log.debug() instead. | |
*/ | |
var console = {}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment