Skip to content
This repository

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' }));
});

Added automatic level detection to connect-logger, depends on http status response, compatible with express 3.x.

  • http responses 3xx, level = WARN
  • http responses 4xx & 5xx, level = ERROR
  • else, level = INFO
  app.use(log4js.connectLogger(logger, { level: 'auto' }));
Something went wrong with that request. Please try again.