From 0968c6709fc8febce1a3320f84cffaa26fa58705 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Tue, 19 Jul 2011 09:08:15 +1000 Subject: [PATCH] fixed connect-logger --- example-connect-logger.js | 4 ++-- lib/connect-logger.js | 2 +- lib/log4js.js | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/example-connect-logger.js b/example-connect-logger.js index 705ef53..b89dc9b 100644 --- a/example-connect-logger.js +++ b/example-connect-logger.js @@ -8,7 +8,7 @@ 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.get('*', function(req,res) { + res.send('hello world\n cheese\n'); }); app.listen(5000); diff --git a/lib/connect-logger.js b/lib/connect-logger.js index fdcf284..395d881 100644 --- a/lib/connect-logger.js +++ b/lib/connect-logger.js @@ -37,7 +37,7 @@ function getLogger(logger4js, options) { var thislogger = logger4js , level = levels.toLevel(options.level, levels.INFO) - , fmt = options.format || ':remote-addr - - ":method :url HTTP/:http-version" :status :content-length ":req[referer]" ":user-agent"'; + , fmt = options.format || ':remote-addr - - ":method :url HTTP/:http-version" :status :content-length ":referrer" ":user-agent"'; return function (req, res, next) { diff --git a/lib/log4js.js b/lib/log4js.js index e0ae439..207003d 100644 --- a/lib/log4js.js +++ b/lib/log4js.js @@ -217,9 +217,10 @@ Logger.prototype.removeLevel = function() { delete this.level; }; -Logger.prototype.log = function(logLevel, args) { - var data = Array.prototype.slice.call(args) - , loggingEvent = new LoggingEvent(this.category, logLevel, data, this); +Logger.prototype.log = function() { + var args = Array.prototype.slice.call(arguments) + , logLevel = args.shift() + , loggingEvent = new LoggingEvent(this.category, logLevel, args, this); this.emit("log", loggingEvent); }; @@ -236,7 +237,9 @@ Logger.prototype.isLevelEnabled = function(otherLevel) { Logger.prototype[levelString.toLowerCase()] = function () { if (this.isLevelEnabled(level)) { - this.log(level, arguments); + var args = Array.prototype.slice.call(arguments); + args.unshift(level); + Logger.prototype.log.apply(this, args); } }; } @@ -411,7 +414,7 @@ module.exports = { logLevelFilter: logLevelFilter, layouts: layouts, - connectLogger: require('./connect-logger').connectLogger(this) + connectLogger: require('./connect-logger').connectLogger }; //keep the old-style layouts