Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pino-browser support for hapi-pino #612

Merged
merged 2 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module.exports = pino

var _console = global.console || {}
var stdSerializers = {
mapHttpRequest: mock,
mapHttpResponse: mock,
wrapRequestSerializer: passthrough,
wrapResponseSerializer: passthrough,
req: mock,
res: mock,
err: asErrValue
Expand Down Expand Up @@ -157,6 +161,7 @@ pino.levels = {
}

pino.stdSerializers = stdSerializers
pino.symbols = require('./lib/symbols')

function set (opts, logger, level, fallback) {
var proto = Object.getPrototypeOf(logger)
Expand Down Expand Up @@ -296,4 +301,5 @@ function asErrValue (err) {
}

function mock () { return {} }
function passthrough (a) { return a }
function noop () {}
30 changes: 23 additions & 7 deletions test/browser.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
const test = require('tape')
const fresh = require('fresh-require')
const pinoStdSerializers = require('pino-std-serializers')
const pinoSymbols = require('../lib/symbols')
const pino = require('../browser')

levelTest('fatal')
Expand Down Expand Up @@ -101,22 +103,36 @@ test('exposes LOG_VERSION', ({ end, is }) => {

test('exposes faux stdSerializers', ({ end, ok, same }) => {
ok(pino.stdSerializers)
ok(pino.stdSerializers.req)
ok(pino.stdSerializers.res)
ok(pino.stdSerializers.err)
// make sure faux stdSerializers match pino-std-serializers
for (let serializer in pinoStdSerializers) {
ok(pino.stdSerializers[serializer], `pino.stdSerializers.${serializer}`)
}
// confirm faux methods return empty objects
same(pino.stdSerializers.req(), {})
same(pino.stdSerializers.mapHttpRequest(), {})
same(pino.stdSerializers.mapHttpResponse(), {})
same(pino.stdSerializers.res(), {})

// confirm wrapping function is a passthrough
const noChange = { foo: 'bar', fuz: 42 }
same(pino.stdSerializers.wrapRequestSerializer(noChange), noChange)
same(pino.stdSerializers.wrapResponseSerializer(noChange), noChange)
end()
})

test('exposes err stdSerializer', ({ end, ok }) => {
ok(pino.stdSerializers)
ok(pino.stdSerializers.req)
ok(pino.stdSerializers.res)
ok(pino.stdSerializers.err)
ok(pino.stdSerializers.err(Error()))
end()
})

test('exposes real symbols', ({ end, ok, same }) => {
ok(pino.symbols)
// confirm every symbol is present
for (let symbol in pinoSymbols) {
ok(pino.symbols[symbol], `pino.symbols.${symbol}`)
}
// confirm real symbols are used
same(pino.symbols, pinoSymbols)
end()
})

Expand Down