From 25c543f8ae94e43e471874b573d1d4fd762c7187 Mon Sep 17 00:00:00 2001 From: Christo Fogelberg Date: Tue, 10 Mar 2015 06:18:02 +0000 Subject: [PATCH] lib/connect-logger.js - allow options.tokens --- lib/connect-logger.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/connect-logger.js b/lib/connect-logger.js index 8162b50..a53f7e0 100644 --- a/lib/connect-logger.js +++ b/lib/connect-logger.js @@ -89,12 +89,12 @@ function getLogger(logger4js, options) { if(res.statusCode >= 400) level = levels.ERROR; } if (thislogger.isLevelEnabled(level)) { - var default_tokens = assemble_tokens(req, res); + var combined_tokens = assemble_tokens(req, res, options.tokens || []); if (typeof fmt === 'function') { - var line = fmt(req, res, function(str){ return format(str, default_tokens); }); + var line = fmt(req, res, function(str){ return format(str, combined_tokens); }); if (line) thislogger.log(level, line); } else { - thislogger.log(level, format(fmt, default_tokens)); + thislogger.log(level, format(fmt, combined_tokens)); } } }); @@ -113,7 +113,19 @@ function getLogger(logger4js, options) { * @param {Array} custom_tokens [{ token: string-or-regexp, replacement: string-or-replace-function }] * @return {Array} */ -function assemble_tokens(req, res) { +function assemble_tokens(req, res, custom_tokens) { + var array_unique_tokens = function(array) { + var a = array.concat(); + for(var i=0; i