Skip to content

Commit

Permalink
Merge pull request #5 from jyotman/fix-pino-constructor
Browse files Browse the repository at this point in the history
fix pino initialisation and take options for pino from user
  • Loading branch information
mcollina authored May 30, 2017
2 parents 3e719bf + e203a14 commit 5d7d966
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ opts can contain:
`servers`.
* `instance`: the instance of [aedes][aedes]
* `messages`: logs all the mqtt PUBLISH received, defaults `true`
* `pinoOptions`: options specific to [Pino](https://github.com/pinojs/pino/blob/master/docs/API.md#parameters)

## License

Expand Down
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ function logging (opts) {
opts = opts || {}

opts.stream = opts.stream || process.stdout
var logger = pino(opts.stream, {
level: opts.level,
extreme: opts.extreme,
safe: opts.safe
})
var logger = pino(opts.pinoOptions || {}, opts.stream)
var instance = opts.instance
var servers = opts.servers

Expand Down
19 changes: 18 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ function startServer (stream, opts, cb) {

var instance = aedes()
var server = opts.createServer(instance.handle)
var pinoOptions = opts.pinoOptions || {}

logging({
instance: instance,
stream: stream,
server: server,
messages: opts.messages
messages: opts.messages,
pinoOptions: pinoOptions
})

server.listen(0, function (err) {
Expand Down Expand Up @@ -340,3 +342,18 @@ test('do not crash if a client does not issue a CONNECT', function (t) {
})
})
})

test('peno options working', function (t) {
t.plan(5)

var dest = sink(function (line, enc, cb) {
t.equal(line.name, 'test logger', 'set pino name property')
t.equal(line.time, undefined, 'disable pino timestamp property')
cb()
})
startServer(dest, {pinoOptions: {name: 'test logger', timestamp: false}}, function (err, server, instance) {
t.error(err)
server.close(t.pass.bind(t, 'server closes'))
instance.close(t.pass.bind(t, 'instance closes'))
})
})

0 comments on commit 5d7d966

Please sign in to comment.