Skip to content

Commit

Permalink
update pino-http to ^4.1.0
Browse files Browse the repository at this point in the history
- remove explicit log statement in favor of providing res.err and
  err.status as recognized by pino-http
- added pino ^5.12.0 as a devDependency to support extreme mode
  benchmark
  • Loading branch information
jstewmon committed Apr 3, 2019
1 parent 91ddec0 commit b4d5329
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
3 changes: 2 additions & 1 deletion benchmarks/pino-extreme-server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict'

var Koa = require('koa')
var pino = require('pino')
var logger = require('../')

var app = new Koa()
app.use(logger({extreme: true}))
app.use(logger(pino.extreme()))

app.use((ctx) => {
ctx.body = 'hello world'
Expand Down
19 changes: 10 additions & 9 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ module.exports = logger

function logger (opts, stream) {
var wrap = pinoHttp(opts, stream)

function pino (ctx, next) {
wrap(ctx.req, ctx.res)
ctx.log = ctx.request.log = ctx.response.log = ctx.req.log
return next().catch(function (e) {
ctx.log.error({
res: ctx.res,
err: {
type: e.constructor.name,
message: e.message,
stack: e.stack
},
responseTime: ctx.res.responseTime
}, 'request errored')
if ('status' in e && !('statusCode' in e)) {
Object.defineProperty(e, 'statusCode', {
get () { return e.status }
})
}
Object.defineProperty(ctx.res, 'err', {
get () { return e }
})
throw e
})
}

pino.logger = wrap.logger
return pino
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
},
"homepage": "https://github.com/davidmarkclements/koa-pino-logger#readme",
"dependencies": {
"pino-http": "^2.0.1"
"pino-http": "^4.1.0"
},
"devDependencies": {
"koa": "^2.0.0",
"koa": "^2.7.0",
"koa-bunyan-logger": "^2.0.0",
"koa-logger": "^3.0.0",
"koa-morgan": "^1.0.0",
"split2": "^2.0.1",
"standard": "^10.0.0",
"tap": "^5.7.1"
"pino": "^5.12.0",
"split2": "^3.1.1",
"standard": "^12.0.1",
"tap": "^12.6.1"
}
}
11 changes: 1 addition & 10 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,7 @@ test('supports errors in the middleware', function (t) {
t.ok(line.err, 'err is defined')
t.equal(line.err.message, 'boom!', 'err message is boom!')
t.equal(line.msg, 'request errored', 'message is request errored')
dest.once('data', function (line) {
// logging the 500 response:
t.ok(line.req, 'req is defined')
t.ok(line.res, 'res is defined')
t.notOk(line.err, 'err is not defined')
t.equal(line.msg, 'request completed', 'message is request completed')
t.equal(line.req.method, 'GET', 'method is get')
t.equal(line.res.statusCode, 500, 'statusCode is 500')
t.end()
})
t.end()
})
})

Expand Down

0 comments on commit b4d5329

Please sign in to comment.