Created
October 31, 2012 03:42
-
-
Save MatthaeusHarris/3984672 to your computer and use it in GitHub Desktop.
Environment variable-based logger
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
function logger() { | |
if (false === (this instanceof logger)) { | |
return new logger(); | |
} else { | |
var logString = process.env.FQDEBUG || ""; | |
logLevels = logString.split(','); | |
for (var l in logLevels) { | |
this.logLevel[logLevels[l]] = true; | |
} | |
console.log(this.logLevel); | |
} | |
} | |
logger.prototype.logLevel = {}; | |
logger.prototype.log = function(level, identifier, text) { | |
if (this.logLevel[level]) { | |
console.log("%s :: %s", identifier, text); | |
} | |
} | |
logger.prototype.info = function(identifier, text) { | |
console.log("%s :: %s", identifier, text); | |
} | |
logger.prototype.error = function(identifier, text) { | |
console.log("ERROR: %s :: %s", identifier, text); | |
} | |
module.exports = logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment