forked from log4js-node/log4js-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Connect Logger
nomiddlename edited this page Jun 1, 2012
·
1 revision
The connect/express logger was added to log4js by danbell. This allows connect/express servers to log using log4js. See example-connect-logger.js.
var log4js = require('./lib/log4js');
log4js.configure({
appenders: [
{ type: 'console' },
{ type: 'file', filename: 'cheese.log', category: 'cheese' }
]
});
var logger = log4js.getLogger('cheese');
logger.setLevel('INFO');
var app = require('express').createServer();
app.configure(function() {
app.use(log4js.connectLogger(logger, { level: log4js.levels.INFO }));
});
app.get('/', function(req,res) {
res.send('hello world');
});
app.listen(5000);The options object that is passed to log4js.connectLogger supports a format string the same as the connect/express logger. For example:
app.configure(function() {
app.use(log4js.connectLogger(logger, { level: log4js.levels.INFO, format: ':method :url' }));
});