{"name":"hapi-pino","version":"5.0.1","description":"Hapi plugin for the Pino logger ","main":"index.js","scripts":{"coverage":"lab test.js -c","coveralls":"lab test.js -r lcov | coveralls","test":"standard && lab --timeout 100000 test.js"},"keywords":["hapi","pino","logger","fast","slow","json"],"license":"MIT","devDependencies":{"code":"^5.2.0","coveralls":"^3.0.2","flush-write-stream":"^1.0.3","hapi":"^17.5.3","lab":"^15.5.0","make-promises-safe":"^1.1.0","pre-commit":"^1.1.2","split2":"^2.2.0","standard":"^11.0.0"},"dependencies":{"abstract-logging":"^1.0.0","hoek":"^5.0.3","pino":"^5.0.1","pino-pretty":"^2.0.1"},"repository":{"type":"git","url":"git+https://github.com/pinojs/hapi-pino.git"},"author":{"name":"David Mark Clements"},"bugs":{"url":"https://github.com/pinojs/hapi-pino/issues"},"homepage":"https://github.com/pinojs/hapi-pino#readme","gitHead":"52be2d81f78ba890cbeb4035d2feb81d492eb983","_id":"hapi-pino@5.0.1","_npmVersion":"6.3.0","_nodeVersion":"8.11.3","_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"dist":{"integrity":"sha512-BhyQXYT54hBPMNXJ0RRcCykIWhhImEUWBz4ZPsUNC2hKT4dHZp6lrb3ByBZZx//qnHxpLvk5rgOyRk6fPz6F6g==","shasum":"32eba7a1a0d44cc03c202800de78f1b296c482de","tarball":"http://registry-npm.ywwl.com/hapi-pino/download/hapi-pino-5.0.1.tgz","fileCount":12,"unpackedSize":40252,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbbFKyCRA9TVsSAnZWagAAkHgP/1d0cnlyIFBTtb6vyRWE\nli5s6yRPcqXmC7ngnBk6HalHdfQ+F+zRmA4Tew4YnB5celuiAIXSE/Mnh9bu\nwK+01framstnXEu79k4d7C+6xe1AGItRIjK4wqocgbK2zy+xUB3/vI2UPy0F\nEP46fVLc21bg7sWUvzKJblwP0DkPI/+SiqS84B7fOpAsuOdPoiByR2nDCOQS\n6RIDqELf2x7bX4Pke0WhXWp83hyVskeb8/eGh/bS9gA/P6j5k90WJJKRtr3l\n20+/hbyKtmXAhH/I+9sVnmU5nslewNrUveonMyyWIx4Om5vV5OqyBFBkoUhF\netB6uHAkEVXxIN1UWHv/VH5o12Vp+AfjezfXijicBq2pEVX84DttRJuUbpAn\n+fi+m+HF9OduyKR+H52hqzm+OvVc2ETrf6aa0WqDZ6Jf+TzI+cL/lSjyoG+i\nfN3SCiWXtI/twiXvpwNK3jJ9I65Kn2Q9fUVvUTIYOLze8xqspJ6nCfz07lA/\nb3b87TGBykXiXDQAu1ZeVPxvnsydz7qR8Hiscr9Z4+JI+woMg9O0YQzBPeQU\nYbMhSfJWjTY9PJUrbwB3URJ1xAQo6ijL4PhGqGLCAvVARldtGmUEbzjuxcV5\nPkAlffu8Axigwqg0f6UihWhB03ZKB2e8Lz6gldyoVu6n8m89F8ErsUlYARrs\nRNyE\r\n=UTs8\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH/hxVUynJY/PWSV7Z95deZ/N5Lvhu0dPCyr9RKCYDViAiEA9qUpNiY/RfLW2wU5k1Rug6fhC1B33eRHrGpEACQeiuM="}],"size":8610,"noattachment":false,"key":"/hapi-pino/-/hapi-pino-5.0.1.tgz"},"maintainers":[{"email":"huperekchuno@googlemail.com","name":"davidmarkclements"},{"email":"james.sumners@gmail.com","name":"jsumners"},{"email":"hello@matteocollina.com","name":"matteo.collina"},{"email":"w@tson.dk","name":"watson"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hapi-pino_5.0.1_1533825713626_0.8139272403718774"},"_hasShrinkwrap":false,"readme":"# hapi-pino&nbsp;&nbsp;![Tests Status](https://github.com/pinojs/hapi-pino/actions/workflows/test.yml/badge.svg)\n\n\n[Hapi](http://hapijs.com) plugin for the [Pino](https://github.com/pinojs/pino) logger. It logs in JSON for easy\npost-processing.\n\n## Hapi and Pino versions supported by hapi-pino\n\n| hapi-pino     | hapi          | pino          |\n| ------------- |:--------------|:--------------|\n| v12.x         | v21           | v8            |\n| v11.x         | v20           | v8            |\n| v9.x - v10.x  | v20           | v7            |\n| v8.x          | v18, v19, v20 | v6            |\n| v6.x          | v17, v18, v19 | v5            |\n| v5.x          | v17, v18      | v5            |\n| v3.x - v4.x   | v17           | v4            |\n| v2.x          | v16           | v4            |\n\n## Install\n\n```\nnpm install hapi-pino\n```\n\n## Usage\n\n```js\n'use strict'\n\nconst Hapi = require('@hapi/hapi')\n\nasync function start () {\n  // Create a server with a host and port\n  const server = Hapi.server({\n    host: 'localhost',\n    port: 3000,\n    debug: false, // disable Hapi debug console logging\n  })\n\n  // Add the route\n  server.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n      // request.log is HAPI standard way of logging\n      request.log(['a', 'b'], 'Request into hello world')\n\n      // you can also use a pino instance, which will be faster\n      request.logger.info('In handler %s', request.path)\n\n      return 'hello world'\n    }\n  })\n\n  await server.register({\n    plugin: require('hapi-pino'),\n    options: {\n      // Redact Authorization headers, see https://getpino.io/#/docs/redaction\n      redact: ['req.headers.authorization']\n    }\n  })\n\n  // also as a decorated API\n  server.logger.info('another way for accessing it')\n\n  // and through Hapi standard logging system\n  server.log(['subsystem'], 'third way for accessing it')\n\n  await server.start()\n\n  return server\n}\n\nstart().catch((err) => {\n  console.log(err)\n  process.exit(1)\n})\n```\n\n## API\n\n- [Options](#options)\n- [Server decorations](#serverdecorations)\n- [Request decorations](#requestdecorations)\n- [Hapi Events](#hapievents)\n\n**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**\n binds to the Hapi events system as described in the [\"Hapi\nevents\"](#hapievents) section.\n\n### Options\n### `options.logPayload: boolean`\n\n  **Default**: `false`\n\n  When enabled, add the request payload as `payload` to the `response` event log.\n\n### `options.logQueryParams: boolean`\n\n  **Default**: `false`\n\n  When enabled, add the request query as `queryParams` to the `response` event log.\n\n### `options.logPathParams: boolean`\n\n  **Default**: `false`\n\n  When enabled, add the request params as `pathParams` to the `response` event log.\n\n### `options.logRouteTags: boolean`\n\n  **Default**: `false`\n\n  When enabled, add the request route tags (as configured in hapi `route.options.tags`) `tags` to the `response` event log.\n\n### `options.log4xxResponseErrors: boolean`\n\n  **Default**: `false`\n\n  When enabled, responses with status codes in the 400-500 range will have the value returned by the hapi lifecycle method added to the `response` event log as `err`.\n\n### `options.logRequestStart: boolean | (Request) => boolean`\n\n  **Default**: false\n\n  Whether hapi-pino should add a `log.info()` at the beginning of Hapi requests for the given Request.\n\n  For convenience, you can pass in `true` to always log `request start` events, or `false` to disable logging `request start` events\n\n  Note: when `logRequestStart` is enabled and `getChildBindings` is configured to omit the `req` field, then the `req` field will be\n  omitted from the `request completed` log event but the `req` field will always be there for the start log. This behavior is useful if you want to separate requests from responses and link the\n  two via requestId (frequently done via `headers['x-request-id']`) , where \"request start\" only logs the request and a requestId,\n  and `request completed` only logs the response and the requestId.\n\n### `options.customRequestStartMessage`\n\n  **Default**: 'request start'\n\n  Set to a `function (request) => { /* returns message string */ }`. This function will be invoked at each request received, setting \"msg\" property to returned string. If not set, default value will be used.\n\n### `options.logRequestComplete: boolean | (Request) => Boolean`\n\n  **Default**: true\n\n  Whether hapi-pino should add a `log.info()` at the completion of Hapi requests for the given Request.\n\n  For convenience, you can pass in `true` to always log `request complete` events, or `false` to disable logging `request complete` events\n\n### `options.customRequestCompleteMessage`\n\n  **Default**: '[response] ${request.method} ${request.path} ${request.raw.res.statusCode} (${responseTime}ms)'\n\n  Set to a `function (request, responseTime) => { /* returns message string */ }`. This function will be invoked at each completed request, setting \"msg\" property to returned string. If not set, default value will be used.\n\n### `options.customRequestErrorMessage`\n\n  **Default**: `error.message`\n\n  Set to a `function (request, err) => { /* returns message string */ }`. This function will be invoked at each failed request, setting \"msg\" property to returned string. If not set, default value will be used.\n\n### `options.stream` Pino.DestinationStream\n\n  **Default**: `process.stdout`\n\n  the binary stream to write stuff to\n\n### `options.tags: ({ [key in pino.Level]?: string })`\n\n  **Default**: exposed via `hapi-pino.levelTags`\n\n  A map to specify pairs of Hapi log tags and levels.  The tags `trace`, `debug`, `info`, `warn`, and `error` map to their corresponding level.\n  Any mappings you supply take precedence over the default mappings.\n\n### `options.allTags: pino.Level`\n\n  **Default**: `'info'`\n\n The logging level to apply to all tags not matched by `tags`\n\n### `options.serializers: { [key: string]: pino.SerializerFn }`\n\n An object to overwrite the default serializers. You can but don't have to overwrite all of them.\n\n **Example**:  \n To redact the authorization header in the logs:\n\n  ```js\n  {\n    req: require('pino-noir')(['req.headers.authorization']).req\n    res: ...\n    err: ...\n  }\n  ```\n\n### `options.wrapSerializers: boolean`\n\n  **Default**: `true`\n\n  When `false`, custom serializers will be passed the raw value directly.\n\n  **Example**:\n  If you prefer to work with the raw value directly, or you want to honor the custom serializers already defined by `options.instance`, you can pass in `options.wrapSerializers` as `false`:\n\n  ```js\n  {\n    wrapSerializers: false,\n    serializers: {\n      req (req) {\n        // `req` is the raw hapi's `Request` object, not the already serialized request from `pino.stdSerializers.req`.\n        return {\n          message: req.foo\n        };\n      }\n    }\n  }\n  ```\n\n### `options.instance: Pino`\n\n  Uses a previously created Pino instance as the logger.\n  The instance's `stream` and `serializers` take precedence.\n\n### `options.logEvents: string[] | false | null`\n\n  **Default**: `['onPostStart', 'onPostStop', 'response', 'request-error']` (all events)\n\n  Takes an array of strings with the events to log.\n\n  Set to `false/null` to disable all events. Even though there is no `request-error` [Hapi Event](#hapievents), the options enables the logging of failed requests.\n\n### `options.mergeHapiLogData: boolean`\n\n  **Default**: `false`\n\n  When enabled, Hapi-pino will merge the data received\n  from Hapi's logging interface (`server.log(tags, data)` or `request.log(tags, data)`)\n  into Pino's logged attributes at root level. If data is a string, it will be used as the value for the `msg` key.\n  When disabled, Hapi-pino will keep data under a `data` key.\n\n  **Example**:  \n  ```js\n  server.log(['info'], {hello: 'world'})\n\n  // with mergeHapiLogData: true\n  { level: 30, hello: 'world', ...}\n\n  // with mergeHapiLogData: false (Default)\n  { level: 30, data: { hello: 'world' }}\n  ```\n\n### `options.getChildBindings: (request) => { [key]: any }`\n\n  **Default**: `() => { req: Request }`, which automatically adds the request to every pino log call\n\n  Takes a function with the request as an input, and returns the object that will be passed into pinoLogger.child().\n\n  Note: Omitting `req` from the child bindings will omit it from all logs, most notably the response log, except \"request start\".\n\n### `options.ignorePaths: string[]`\n  Takes an array of string routes and disables logging for each.  Useful for health checks or any route that does not need logging.\n\n  **Example**:  \n  Do not log for /health route\n  ```js\n  ignorePaths: ['/health']\n  ```\n\n### `options.ignoreTags: string[]`\n  Takes an array of string tags and disables logging for each.  Useful for health checks or any route that does not need logging.\n\n  **Example**:  \n  Do not log for route with `healthcheck` tag\n  ```js\n  ignoreTags: ['healthcheck']\n  ```\n\n### `options.ignoreFunc: (options, request) => boolean`\n  Takes a function that receives the plugin options and the request as parameters, and returns a boolean. Logging will be disabled if the return value is `true`. Useful for scenarios where the `ignorePaths` or `ignoreTags` options can't achieve what is intended.\n\n  **Example**:\n  Do not log routes relative to static content\n  ```js\n  ignoreFunc: (options, request) => request.path.startsWith('/static')\n  ```\n\n  **Note**: if `ignoreFunc` is used, the other two options that can be used to ignore / disable logging (`ignorePaths` and `ignoreTags`) are effectively discarded. So `ignoreFunc` can be seen a more advanced option. For instance, you can easily re-implement the `ignorePaths` functionality as follows:\n\n  ```js\n  ignoreFunc: (options, request) => myIgnorePaths.include(request.path)\n  ```\n\n  (where `myIgnorePaths` would be an array with paths to be ignored).\n\n\n### `options.ignoredEventTags: object[]`\n  Takes an array of object tags and disables logging for each.  Useful for debug logs or any other tags that does not need logging.\n\n  **Default**: `{ log: '*', request: '*' }`, Logs all the events emitted by server.log and request.log without filtering event tags\n\n  **Example**:\n  Do not log the events for DEBUG and TEST tag\n  ```js\n  ignoredEventTags: { log: ['DEBUG', 'TEST'], request: ['DEBUG', 'TEST'] }\n  server.log(['DEBUG'], 'DEBUG')\n  ```\n\n\n### `options.level: Pino.Level`\n  **Default**: `'info'`\n\n  Set the minimum level that Pino should log out. See [Level](https://github.com/pinojs/pino/blob/master/docs/api.md#level).\n\n  **Example**:  \n  Configure Pino to output all `debug` or higher events:\n  ```js\n  level: 'debug'\n  ```\n\n### `options.redact: string[] | pino.redactOptions`\n\n  Path to be redacted in the log lines. See the [log redaction](https://getpino.io/#/docs/redaction) docs for more details.\n\n<a name=\"serverdecorations\"></a>\n### Server Decorations\n\n**hapi-pino** decorates the Hapi server with `server.logger`, which is an instance of\n  [pino][pino]. See its doc for the way to actual log.\n\n<a name=\"requestdecorations\"></a>\n### Request Decorations\n\n**hapi-pino** decorates the Hapi request with:\n\n- `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.\n\n<a name=\"hapievents\"></a>\n### Hapi Events\n\n**hapi-pino** listens to some Hapi events:\n\n- `'onRequest'`, to create a request-specific child logger\n- `'response'`, to log at `'info'` level when a request is completed\n- `'request'`, to support logging via the Hapi `request.log()` method and to log at `'warn'` level when a request errors or when request received contains an invalid `accept-encoding` header, see `tags` and `allTags` options.\n- `'log'`, to support logging via the Hapi `server.log()` method and to log in case of an internal server event, see `tags` and `allTags` options.\n- `'onPostStart'`, to log when the server is started\n- `'onPostStop'`, to log when the server is stopped\n\n## Acknowledgements\n\nThis project was kindly sponsored by [nearForm](http://nearform.com).\n\n## License\n\nMIT\n\n[pino]: https://github.com/pinojs/pino\n","publish_time":1533825713744,"_cnpm_publish_time":1533825713744,"dist-tags":{"latest":"13.0.0","version16":"2.3.0"}}