From 41504a755d0b6cd0627ae9e80871b4c6242e4cf3 Mon Sep 17 00:00:00 2001 From: Christo Fogelberg Date: Tue, 10 Mar 2015 06:37:53 +0000 Subject: [PATCH] test/connect-logger-test.js - tests for custom tokens --- test/connect-logger-test.js | 45 ++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/test/connect-logger-test.js b/test/connect-logger-test.js index 1f50416..dd1e717 100644 --- a/test/connect-logger-test.js +++ b/test/connect-logger-test.js @@ -246,7 +246,50 @@ vows.describe('log4js connect logger').addBatch({ 'should output the response header': function(messages) { assert.equal(messages[0].message, 'application/cheese'); } - } + }, + 'log events with custom token' : { + topic: function(clm) { + var ml = new MockLogger(); + var cb = this.callback; + ml.level = levels.INFO; + var cl = clm.connectLogger(ml, { level: levels.INFO, format: ':method :url :custom_string', tokens: [{ + token: ':custom_string', replacement: 'fooBAR' + }] } ); + request(cl, 'GET', 'http://url', 200); + setTimeout(function() { + cb(null, ml.messages); + },10); + }, + + 'check message': function(messages) { + assert.isArray(messages); + assert.equal(messages.length, 1); + assert.ok(levels.INFO.isEqualTo(messages[0].level)); + assert.equal(messages[0].message, 'GET http://url fooBAR'); + } + }, + + 'log events with custom override token' : { + topic: function(clm) { + var ml = new MockLogger(); + var cb = this.callback; + ml.level = levels.INFO; + var cl = clm.connectLogger(ml, { level: levels.INFO, format: ':method :url :date', tokens: [{ + token: ':date', replacement: "20150310" + }] } ); + request(cl, 'GET', 'http://url', 200); + setTimeout(function() { + cb(null, ml.messages); + },10); + }, + + 'check message': function(messages) { + assert.isArray(messages); + assert.equal(messages.length, 1); + assert.ok(levels.INFO.isEqualTo(messages[0].level)); + assert.equal(messages[0].message, 'GET http://url 20150310'); + } + } } }).export(module);