Skip to content

Commit

Permalink
Merge pull request #5 from mcollina/pretty-print
Browse files Browse the repository at this point in the history
Added the ability to prettyPrint the logs
  • Loading branch information
mcollina committed Apr 22, 2016
2 parents 2633c09 + 4fef0f1 commit 16f5cd0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ events"](#hapievents) section.

- `[stream]` - the binary stream to write stuff to, defaults to
`process.stdout`.
- `[prettyPrint]` - pretty print the logs (same as `node server |
pino`), disable in production. Default is `false`, enable in
development by passing `true`.
- `[tags]` - a map to specify pairs of Hapi log tags and levels.
- `[allTags]` - the logging level to apply to all tags not matched by
`tags`, defaults to `'info'`.
Expand Down
7 changes: 6 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ server.route({
}
})

server.register(require('.'), (err) => {
server.register({
register: require('.').register,
options: {
prettyPrint: process.env.NODE_ENV !== 'production'
}
}, (err) => {
if (err) {
console.error(err)
process.exit(1)
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ function register (server, options, next) {
return next(new Error('invalid tag levels'))
}

const logger = pino(options, options.stream)
let stream = options.stream || process.stdout

if (options.prettyPrint) {
let pretty = pino.pretty()
pretty.pipe(stream)
stream = pretty
}

const logger = pino(options, stream)

// expose logger as 'server.app.logger'
server.app.logger = logger
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"standard": "^6.0.8"
},
"dependencies": {
"pino": "^2.1.4"
"pino": "^2.2.0"
}
}

0 comments on commit 16f5cd0

Please sign in to comment.