Created
June 11, 2015 16:14
-
-
Save assertnotnull/a0813ff2ed1da32ede6e to your computer and use it in GitHub Desktop.
somewhat reusable socket 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
//somewhat reusable module socketlogger - it requires the usage of global.socket | |
//so it's not passed to every log function. | |
function SocketLogger() {} | |
var getLogger = function(categoryName) { | |
SocketLogger.prototype = log4js.getLogger(categoryName); | |
['Trace','Debug','Info','Warn','Error','Fatal', 'Mark'].forEach( | |
function (levelString) { | |
var level = log4js.levels.toLevel(levelString); | |
SocketLogger.prototype[levelString.toLowerCase()] = function() { | |
var args = Array.prototype.slice.call(arguments); | |
if (global.socket) | |
args.unshift(global.socket.id + ' - '); | |
args.unshift(level); | |
SocketLogger.prototype.log.apply(this, args); | |
} | |
} | |
); | |
return new SocketLogger(); | |
}; | |
module.exports = { | |
getLogger: getLogger | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment