{"id":24383430,"url":"https://github.com/firstandthird/hapi-log-response","last_synced_at":"2025-04-11T01:12:28.986Z","repository":{"id":21775766,"uuid":"25098077","full_name":"firstandthird/hapi-log-response","owner":"firstandthird","description":"Hapi plugin to log responses based on status code","archived":false,"fork":false,"pushed_at":"2023-01-07T22:22:38.000Z","size":803,"stargazers_count":2,"open_issues_count":15,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-11T01:12:22.932Z","etag":null,"topics":["hapi-plugin","hapi-v17"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firstandthird.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-11T22:42:49.000Z","updated_at":"2021-03-19T16:27:52.000Z","dependencies_parsed_at":"2023-01-13T21:40:25.351Z","dependency_job_id":null,"html_url":"https://github.com/firstandthird/hapi-log-response","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-log-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-log-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-log-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-log-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/hapi-log-response/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322571,"owners_count":21084337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hapi-plugin","hapi-v17"],"created_at":"2025-01-19T10:14:27.970Z","updated_at":"2025-04-11T01:12:28.965Z","avatar_url":"https://github.com/firstandthird.png","language":"JavaScript","readme":"\u003ch1 align=\"center\"\u003ehapi-log-response\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/firstandthird/hapi-log-response/actions\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/workflow/status/firstandthird/hapi-log-response/Test/main?label=Tests\u0026style=for-the-badge\" alt=\"Test Status\"/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/firstandthird/hapi-log-response/actions\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/workflow/status/firstandthird/hapi-log-response/Lint/main?label=Lint\u0026style=for-the-badge\" alt=\"Lint Status\"/\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/npm/v/hapi-log-response.svg?label=npm\u0026style=for-the-badge\" alt=\"NPM\" /\u003e\n\u003c/p\u003e\n\n\nA [hapi](https://hapi.dev/) plugin that uses the [server.log()](https://hapi.dev/api/?v=20.1.0#-serverlogtags-data-timestamp) function to log requests/responses based on their statusCode.  By default it will only log redirects (HTTP 301/302) and errors (HTTP 400-500), but you can customize it to include/exclude any status code you want, or just have it log all requests regardless of code.\n\n## Installation\n\n```sh\nnpm install hapi-log-response\n```\n\n_or_\n\n```sh\nyarn add hapi-log-response\n```\n\n## Usage\n\nRegister just like any other hapi plugin:\n\n```javascript\nawait server.register({\n  plugin: require('hapi-log-response'),\n  options: {}\n});\n```\n\n```js\nserver.route({\n  method: 'GET',\n  path: '/error',\n  handler(request, h) {\n    throw boom.badRequest('HELLO WORLD');\n  }\n});\n```\n\n  Calling that route will result in something like the following log:\n  ```\n  [ 'detailed-response', 'user-error', 'bad-request' ]\n  {\n   browser: 'Other 0.0.0 / Other 0.0.0',\n   userAgent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',\n   isBot: false,\n   ip: '127.0.0.1',\n   method: 'get',\n   path: '/error',\n   query: {},\n   message: '/error: HELLO WORLD',\n   statusCode: 400,\n   error: {\n     message: 'HELLO WORLD',\n     stack: 'Error: HELLO WORLD\\n\n        at handler (/script.js:26:12)\n        ....'\n  ```\n\n## Default tags\n\nhapi-log-response will add the following tags to the log depending on the HTTP status of the request:\n\n- _301_ 'redirect'\n- _302_ 'redirect'\n- _400_ 'bad-request'\n- _401_ 'unauthorized'\n- _500_ 'internal-server'\n- _503_ 'service-unavailable'\n- _504_ 'client-timeout'\n\nAdditionally hapi-log-response will add the 'detailed-response'\ntag to every log it enters, unless you requested something different using the _tag_ option (see below).\n\n\n## Options\n\nYou can configure hapi-log-response by configuring the following options when you register the plugin:\n\n- _requests_\n\n   By default hapi-log-responses only responds when the request results in either a redirect (HTTP 301 or 302) or an error (anything between HTTP 400 through HTTP 500).  Set this option to true to always log all requests regardless of HTTP status.  Setting this will override the _excludeStatus_ option.\n\n- _requiredTags_\n\n  An array of tags to match, tags that don't match this will not be logged.\n\n- _excludeStatus_\n\n  An array of HTTP statuses you want to ignore.  Responses that match any of these statusCodes will not be logged.  However the _requests_ option logs everything and will override this if set to true.\n\n- _includeId_\n\n  Will include the hapi-assigned ID for the request, default is false.\n\n- _ignoreUnauthorizedTry_\n\n  By default hapi-log-response will log any time a client tries to access a protected route.  This can get really obnoxious when your server is being probed by the various crawlers and bots running around the Internet, so set this to 'true' to ignore those failed attempts.\n\n- _includeEventTags_\n\n  By default event tags like `handler` are not logged, set this option to true to see them.\n\n- _requestPayload_\n\n  For POST routes, you can opt to also log the incoming request payload.  Default is false.\n\n- _requestHeaders_\n\n  Setting this option to true will cause request headers to be included in the logs.  By default they are not included.\n\n- _tags_\n\n  An array containing zero or more strings that will be added to the list of tags accompanying the log. If not specified, the default is `['detailed-response']`.\n\n\n---\n\n\u003ca href=\"https://firstandthird.com\"\u003e\u003cimg src=\"https://firstandthird.com/_static/ui/images/safari-pinned-tab-62813db097.svg\" height=\"32\" width=\"32\" align=\"right\"\u003e\u003c/a\u003e\n\n_A [First + Third](https://firstandthird.com) Project_\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-log-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fhapi-log-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-log-response/lists"}