1.0.2 • Published 7 years ago

mw-hapi-pino v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

mw-hapi-pino

Registers the Pino logger.

This is a fork of the hapi-pino project.

Options

  • [extensions] - an object extending logging capabilities under specified conditions. The object has the extensions name as key and an array of applicable conditions as value, for example: { responsePayload: ['urlfragment'] }. Supported extensions: responsePayload - logs response payload for requests coming to the specified urls).
  • [level] - the logging level, can be one of trace, debug, info, warn, and error.
  • [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. By default, the tags trace, debug, info, warn, and error map to their corresponding level. Any mappings you supply take precedence over the default mappings. The default level tags are exposed via hapi-pino.levelTags.
  • [allTags] - the logging level to apply to all tags not matched by tags, defaults to 'info'.
  • [instance] - uses a previously created Pino instance as the logger. The instance's stream and serializers take precedence.
  • [logEvents] - Takes an array of strings with the events to log. Default is to log all events e.g. ['onPostStart', 'onPostStop', 'response', 'request-error']. Set to false/null to disable all events.
  • [mergeHapiLogData] - When enabled, Hapi-pino will merge the data received from Hapi's logging interface (server.log(tags, data) or request.log(tags, data)) into Pino's logged attributes at root level. If data is a string, it will be used as the value for the msg key. Default is false, in which case data will be logged under a data key.

Decorations

The Hapi server is decorated with:

  • server.logger(), which is a function that returns the current instance of 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.

The Hapi request object is decorated with:

  • request.logger, which is an instance of pino bound to the current request, so you can trace all the logs of a given request.