Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pinojs/pino-http
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Feb 5, 2023
2 parents 11f9476 + 9d17cfb commit b89d732
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ function pinoLogger (opts, stream) {
function onResFinished (res, logger, err) {
let log = logger
const responseTime = Date.now() - res[startTime]
const level = getLogLevelFromCustomLogLevel(customLogLevel, useLevel, res, err)
const req = res[reqObject]
const level = getLogLevelFromCustomLogLevel(customLogLevel, useLevel, res, err, req)

if (level === 'silent') {
return
}

const req = res[reqObject]

const customPropBindings = (typeof customProps === 'function') ? customProps(req, res) : customProps
if (customPropBindings) {
log = logger.child(customPropBindings)
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ test('uses the custom log level passed in as an option', function (t) {
})
})

test('uses the custom log level passed in as an option, req and res is defined', function (t) {
const dest = split(JSON.parse)
const logger = pinoHttp({
customLogLevel: function (_req, _res, _err) {
t.ok(_req, 'req is defined')
t.ok(_res, 'res is defined')

return 'warn'
}
}, dest)

setup(t, logger, function (err, server) {
t.error(err)
doGet(server)
})
dest.on('data', function () {
t.end()
})
})

test('uses the log level passed in as an option, where the level is a custom one', function (t) {
const dest = split(JSON.parse)
const logger = pinoHttp(
Expand Down

0 comments on commit b89d732

Please sign in to comment.