hmpo-logger
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -192,2 +192,11 @@ var winston = require('winston'), | ||
strippedRequest: new TokenFn(function () { | ||
if (!this.req) { return; } | ||
var url = this.req.originalUrl || this.req.url; | ||
if (typeof url === 'string') { | ||
url = url.split('?')[0]; | ||
} | ||
return url; | ||
}), | ||
httpVersion: new TokenFn(function () { | ||
@@ -194,0 +203,0 @@ if (!this.req || !this.req.httpVersionMajor || !this.req.httpVersionMinor) { return; } |
@@ -20,3 +20,3 @@ var winston = require('winston'), | ||
console: true, | ||
connsoleJSON: false, | ||
consoleJSON: false, | ||
consoleLevel: 'debug', | ||
@@ -151,3 +151,3 @@ consoleColor: true, | ||
logstash: false, | ||
formatter: this._options.appJSON ? logstash : undefined, | ||
formatter: this._options.errorJSON ? logstash : undefined, | ||
level: this._options.errorLevel | ||
@@ -188,7 +188,9 @@ }) | ||
Manager.prototype.middleware = function () { | ||
Manager.prototype.middleware = function (name) { | ||
var options = this.getGlobal()._options; | ||
var logger = this.get(':express'); | ||
name = name || ':express'; | ||
var logger = this.get(name); | ||
var timeDiff = function (from, to) { | ||
@@ -195,0 +197,0 @@ var ms = (to[0] - from[0]) * 1e3 |
{ | ||
"name": "hmpo-logger", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Consistent logging for hmpo apps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -275,2 +275,81 @@ | ||
describe('request', function () { | ||
it('should return the full request URL', function () { | ||
var meta = { | ||
req: { | ||
originalUrl: '/test/path?query=string', | ||
url: '/path' | ||
} | ||
}; | ||
Logger.tokens.request.fn.call(meta) | ||
.should.equal('/test/path?query=string'); | ||
}); | ||
it('should return the url if originaUrl is not present', function () { | ||
var meta = { | ||
req: { | ||
url: '/path' | ||
} | ||
}; | ||
Logger.tokens.request.fn.call(meta) | ||
.should.equal('/path'); | ||
}); | ||
}); | ||
describe('strippedRequest', function () { | ||
it('should return originalUrl without the query string', function () { | ||
var meta = { | ||
req: { | ||
originalUrl: '/test/path?query=string', | ||
url: '/path' | ||
} | ||
}; | ||
Logger.tokens.strippedRequest.fn.call(meta) | ||
.should.equal('/test/path'); | ||
}); | ||
it('should return url without the query string if orginalUrl is not present', function () { | ||
var meta = { | ||
req: { | ||
url: '/test/path?query=string' | ||
} | ||
}; | ||
Logger.tokens.strippedRequest.fn.call(meta) | ||
.should.equal('/test/path'); | ||
}); | ||
it('should return a url that has no query string', function () { | ||
var meta = { | ||
req: { | ||
originalUrl: '/test/path', | ||
url: '/path' | ||
} | ||
}; | ||
Logger.tokens.strippedRequest.fn.call(meta) | ||
.should.equal('/test/path'); | ||
}); | ||
it('should return the url if originaUrl is not present', function () { | ||
var meta = { | ||
req: { | ||
url: '/path' | ||
} | ||
}; | ||
Logger.tokens.strippedRequest.fn.call(meta) | ||
.should.equal('/path'); | ||
}); | ||
it('should return undefined if neither is present', function () { | ||
var meta = { | ||
req: {} | ||
}; | ||
expect(Logger.tokens.strippedRequest.fn.call(meta)).to.be.undefined; | ||
}); | ||
it('should return undefined if req is not present', function () { | ||
var meta = {}; | ||
expect(Logger.tokens.strippedRequest.fn.call(meta)).to.be.undefined; | ||
}); | ||
}); | ||
describe('httpVersion', function () { | ||
@@ -277,0 +356,0 @@ it('should return formatted http version', function () { |
@@ -163,2 +163,12 @@ | ||
it('should log using label of :express', function () { | ||
manager.middleware(); | ||
manager.get.should.have.been.calledWithExactly(':express'); | ||
}); | ||
it('should log using given logger name as label', function () { | ||
manager.middleware('customname'); | ||
manager.get.should.have.been.calledWithExactly('customname'); | ||
}); | ||
it('should log details from a request', function (done) { | ||
@@ -165,0 +175,0 @@ var middleware = manager.middleware(); |
60120
1427