Skip to content

Commit

Permalink
log no response time when using immediate
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed May 18, 2014
1 parent fcf4ccf commit 3dbd945
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -2,6 +2,7 @@ unreleased
==========

* "dev" format will use same tokens as other formats
* `:response-time` token is now empty when immediate used
* `:response-time` token is now monotonic
* `:response-time` token has precision to 1 μs
* fix `:status` + immediate output in node.js 0.8
Expand Down
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -203,8 +203,8 @@ exports.token('method', function(req){
* response time in milliseconds
*/

exports.token('response-time', function(req){
if (!req._startAt) return '';
exports.token('response-time', function(req, res){
if (!res._header || !req._startAt) return '';
var diff = process.hrtime(req._startAt);
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
return ms.toFixed(3);
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Expand Up @@ -158,6 +158,21 @@ describe('logger()', function () {
done()
})
})

it('should be empty before response', function (done) {
var server = createServer({
format: ':response-time',
immediate: true
})

request(server)
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal('-\n')
done()
})
})
})

describe(':status', function () {
Expand Down

0 comments on commit 3dbd945

Please sign in to comment.