Skip to content

Commit

Permalink
Filled in docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Apr 19, 2016
1 parent 94b7465 commit 5c69110
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,62 @@ server.register(require('hapi-pino'), (err) => {
})
```

## API

- [Options](#options)
- [Server decorations](#serverdecorations)
- [Request decorations](#requestdecorations)
- [Hapi Events](#hapievents)

**hapi-pino** goal is to enable Hapi applications to log via [pino][pino]. To enable this, it decorates both the [server](#serverdecorations) and the [request](#requestadditions). Moreover, **hapi-pino**
binds to the Hapi events system as described in the ["Hapi
events"](#hapievents) section.

### Options

- `[stream]` - the binary stream to write stuff to, defaults to
`process.stdout`.
- `[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'`.


<a name="serverdecorations"></a>
### Server Decorations

**hapi-pino** decorates the Hapi server with:

* `server.logger()`, which is a function that returns the current instance of
[pino][pino], see its doc for the way to actual log.
* `server.app.logger`, same as before, but the logger it is also
attached to the `server.app` object.

<a name="requestdecorations"></a>
### Request Decorations

**hapi-pino** decorates the Hapi request with:

* `request.logger`, which is an instance of [pino][pino] bound to the current request, so you can trace all the logs of a given request. See [pino][pino] doc for the way to actual log.

<a name="hapievents"></a>
### Hapi Events

**hapi-pino** listens to some Hapi events:

* `'onRequest'`, to create a request-specific child logger
* `'response'`, to log at `'info'` level when a request is completed
* `'response-error'`, to log at `'warn'` level when a request errors
* `'log'`, to support logging via the Hapi `server.log()` and
`request.log()` methods, see `tags` and `allTags` options.
* `'onPostStart'`, to log when the server is started
* `'onPostStopt'`, to log when the server is stopped

## Acknowledgements

This project was kindly sponsored by [nearForm](http://nearform.com).

## License

MIT

[pino]: https://github.com/mcollina/pino

0 comments on commit 5c69110

Please sign in to comment.