Created
December 19, 2011 12:35
-
-
Save andrewn/1497027 to your computer and use it in GitHub Desktop.
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
var Logging = (function () { | |
function create(source) { | |
function F() {} | |
F.prototype = source; | |
return new F(); | |
}; | |
var LoggerBase = function (opts) { | |
var opts = opts || {}; | |
this.name = opts.name; | |
}; | |
LoggerBase.prototype = { | |
// Butter's log function | |
debug: function () { this.addLog('debug', arguments); }, | |
// Standard firebug logging | |
log : function () { this.addLog('log' , arguments); }, | |
info : function () { this.addLog('info' , arguments); }, | |
warn : function () { this.addLog('warn' , arguments); }, | |
error: function () { this.addLog('error', arguments); }, | |
messages: { | |
debug : [], | |
log : [], | |
info : [], | |
warn : [], | |
error : [] | |
} | |
}; | |
var SilentLogger = { | |
create: function (opts) { | |
var logger = new LoggerBase(opts); | |
logger.addLog = function (type) { | |
var type = type, | |
args = [].slice.call(arguments, 1); | |
if (this.messages[type]) { | |
this.messages[type].push(args); | |
} | |
} | |
return logger; | |
} | |
}; | |
var ConsoleLogger = { | |
create: function (opts) { | |
var logger = new LoggerBase(opts); | |
logger.addLog = function (type) { | |
var type = type, | |
args = [].slice.call(arguments, 1); | |
if (this.name) { | |
args = [this.name + ':'].concat(args); | |
} | |
if (this.messages[type]) { | |
this.messages[type].push(args); | |
} | |
if (console[type]) { | |
console[type].apply(this, args); | |
} | |
}; | |
return logger; | |
} | |
}; | |
return { | |
SilentLogger : SilentLogger, | |
ConsoleLogger : ConsoleLogger | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment