Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created March 10, 2016 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvanasco/a18eaec1d5714d468349 to your computer and use it in GitHub Desktop.
Save jvanasco/a18eaec1d5714d468349 to your computer and use it in GitHub Desktop.
if (typeof console === 'undefined') {
window.console = {
log: function () {}
};
}
function loggerFactory(label) {
return (function () {
var timestamp = function () {};
timestamp.toString = function () {
var label_line = label;
// this just checks for a certain global var which is only
// set on a Porthole window. lets me test interplay of js loaded
// into an iframe
if (CiPortholeApiWorker && CiPortholeApiWorker.is_worker) {
label_line = 'WORKER][' + label;
}
var port = "[" + window.location.protocol + "]";
return port + "[" + label_line + ' ' + (new Date()).toLocaleTimeString() + "]";
};
if (DEBUG) { return { log: console.log.bind(console, '%s', timestamp) }; }
return { log: function () {} };
})();
}
function loggerFactoryNull(label) {
return(function () { return { log: function () {} }; }());
}
var lwDebug = loggerFactory('web.debug');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment