Skip to content

Instantly share code, notes, and snippets.

@marcello3d
Created March 24, 2011 03:45
Show Gist options
  • Save marcello3d/884530 to your computer and use it in GitHub Desktop.
Save marcello3d/884530 to your computer and use it in GitHub Desktop.
simple log4js wrapper
var log4js = require('log4js')()
log4js.addAppender(log4js.consoleAppender())
/**
* Get a logger. If no name is specified, retrieve the caller's filename
* example:
* var log = require('./log.js')()
*/
module.exports = function(name) {
if (!name) {
//
var split = new Error().stack.split('\n')[2]
var scriptName = /\(([^(:]+):/.exec(split)[1]
name = scriptName.substring(process.cwd().length+1)
}
return log4js.getLogger(name)
}
/**
* Access to the raw log4js object
*/
module.exports.log4js = log4js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment