{"id":28200978,"url":"https://github.com/payu/express-request-logger","last_synced_at":"2025-08-26T15:19:42.269Z","repository":{"id":42224341,"uuid":"80017654","full_name":"PayU/express-request-logger","owner":"PayU","description":"Middleware for logging request/responses in Express apps","archived":false,"fork":false,"pushed_at":"2025-04-14T13:41:15.000Z","size":269,"stargazers_count":43,"open_issues_count":11,"forks_count":21,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-08-09T05:55:24.817Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PayU.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-01-25T13:37:44.000Z","updated_at":"2025-04-14T13:41:18.000Z","dependencies_parsed_at":"2024-06-18T16:41:49.967Z","dependency_job_id":"52ec1431-130d-4c6a-a903-7c3b55ec0ff4","html_url":"https://github.com/PayU/express-request-logger","commit_stats":{"total_commits":93,"total_committers":17,"mean_commits":5.470588235294118,"dds":0.5053763440860215,"last_synced_commit":"fd379d41b334b4870acb088ff1ea71e21461f926"},"previous_names":["ugolas/express-request-logger"],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/PayU/express-request-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Fexpress-request-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Fexpress-request-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Fexpress-request-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Fexpress-request-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PayU","download_url":"https://codeload.github.com/PayU/express-request-logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Fexpress-request-logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272233477,"owners_count":24896822,"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","status":"online","status_checked_at":"2025-08-26T02:00:07.904Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-05-16T22:14:47.450Z","updated_at":"2025-08-26T15:19:42.246Z","avatar_url":"https://github.com/PayU.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM Version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![MIT License][license-image]][license-url]\n\n# express-request-logger\nMiddleware for logging request/responses in Express apps\n\n## Supported features\n- Logging request\n- Logging response\n- Mask request body fields\n- Exclude request body fields\n- Exclude request specific headers\n- Mask response body fields\n- Exclude response body fields\n- Exclude response specific headers\n- Exclude specific URLs from logging\n- Supported by Node v8 and above.\n\n## Installation\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```sh\n$ npm install express-requests-logger\n```\n\n## API\n\n```js\nvar audit = require('express-requests-logger')\n```\n\n### audit(options)\n\nCreate an audit middleware with ther given `options`.\n\n#### options\n\nthe `express-requests-logger` accepts the following properties in the options object.\n\n#### logger\n\nThe logger to use for logging the request/response.\nPackage tested only with [bunyan](https://github.com/trentm/node-bunyan) logger, but should work with any logger which has a `info` method which takes an object.\n\n#### shouldSkipAuditFunc\n\nShould be a function, that returns boolean value to indicate whether to skip the audit for the current request. Usually the logic should be around the request/response params. Useful to provide a custom logic for cases we would want to skip logging specific request.\n\nThe default implementation of the function returns false.\n\nExample, skipping logging of all success responses:\n```js\nshouldSkipAuditFunc: function(req, res){\n    let shouldSkip = false;\n    if (res.statusCode === 200){\n        // _bodyJson is added by this package\n        if (res._bodyJson.result === \"success\"){\n            shouldSkip = true;\n        }\n    }\n\n    return shouldSkip;\n}\n```\n#### doubleAudit\n\n`true` - log once the request arrives (request details), and log after response is sent (both request and response). - Useful if there is a concern that the server will crash during the request and there is a need to log the request before it's processed.\n\n`false` - log only after the response is sent.\n#### excludeURLs\n\nArray of strings - if the request url matches one of the values in the array, the request/response won't be logged.\nFor example: if there is a path `/v1/health` that we do not want to log, add:\n```js\nexcludeURLs: ['health']\n```\n#### request\n\nSpecific configuration for requests\n##### audit\n\nBoolean - `true` - include request in audit, `false` - don't.\n\n##### excludeBody\n\nArray of strings - pass the fields you wish to exclude in the body of the requests (sensitive data like passwords, credit cards numbers etc..).\n`*` field - exclude all body\n\n##### maskBody\n\nArray of strings - pass the fields you wish to mask in the body of the requests (sensitive data like passwords, credit cards numbers etc..).\n\n##### maskQuery\n\nArray of strings - pass the fields you wish to mask in the query of the requests (sensitive data like passwords, credit cards numbers etc..).\n##### excludeHeaders\n\nArray of strings - pass the header names you wish to exclude from the audit (senstitive data like authorization headers etc..).\n`*` field - exclude all headers\n\n##### maskHeaders\n\nArray of strings - pass the fields you wish to mask in the headers of the requests (senstitive data like authorization headers etc..).\n\n ##### maxBodyLength\n\n Restrict request body's logged content length (inputs other than positive integers will be ignored).\n\n##### customMaskBodyFunc\n\n Additional to mask options, you can add your own functionality to mask request body. This function will execute \n as a masking function before the package functions.\n The custom function gets the full express request and should return the masked body.\n\n#### response\n\nSpecific configuration for responses\n\n**Doesn't print headers for Node below v6.9.2**\n\n**Non JSON responses are not masked, and are logged as is. This is deducted from the response header `content-type`**\n\n##### audit\n\nBoolean - `true` - include response in audit, `false` - don't.\n\n##### excludeBody\n\nArray of strings - pass the fields you wish to exclude in the body of the responses (sensitive data like passwords, credit cards numbers etc..).\n`*` field - exclude all body\n\n##### maskBody\n\nArray of strings - pass the fields you wish to mask in the body of the responses (sensitive data like passwords, credit cards numbers etc..).\n\n##### excludeHeaders\n\nArray of strings - pass the header names you wish to exclude from the audit (senstitive data like authorization headers etc..).\n`*` field - exclude all headers\n\n##### maskHeaders\n\nArray of strings - pass the fields you wish to mask in the headers of the responses (senstitive data like authorization headers etc..).\n\n##### levels\n\nMap of statusCodes to log levels. By default the audit is logged with level 'info'. It is possible to override it by configuration according to the statusCode of the response:\n \n - Key: status code, or status code group: '2xx', '401', etc.. First we try to match by exact match (for example 400), if no key found by exact match we fallback to match bu group (4xx).\n - Value: log level, valid values: 'trace', 'debug', 'info', 'warn', 'error'.\n - Configuration errors are ignored and the log is info by default.\n\n ##### maxBodyLength\n\n Restrict response body's logged content length (inputs other than positive integers will be ignored).\n\n \n Example:\n```\nlevels: {\n    \"2xx\":\"info\", // All 2xx responses are info\n    \"401\":\"warn\", // 401 are warn\n    \"4xx':info\", // All 4xx except 401 are info\n    \"503\":\"warn\",\n    \"5xx\":\"error\" // All 5xx except 503 are errors, 503 is warn,\n}\n```\n\n\n### Example\n\n```js\napp.use(audit({\n    logger: logger, // Existing bunyan logger\n    excludeURLs: [‘health’, ‘metrics’], // Exclude paths which enclude 'health' \u0026 'metrics'\n    request: {\n        maskBody: [‘password’], // Mask 'password' field in incoming requests\n        excludeHeaders: [‘authorization’], // Exclude 'authorization' header from requests\n        excludeBody: [‘creditCard’], // Exclude 'creditCard' field from requests body\n        maskHeaders: [‘header1’], // Mask 'header1' header in incoming requests\n        maxBodyLength: 50 // limit length to 50 chars + '...'\n    },\n    response: {\n        maskBody: [‘session_token’] // Mask 'session_token' field in response body\n        excludeHeaders: [‘*’], // Exclude all headers from responses,\n        excludeBody: [‘*’], // Exclude all body from responses\n        maskHeaders: [‘header1’], // Mask 'header1' header in incoming requests\n        maxBodyLength: 50 // limit length to 50 chars + '...'\n    },\n    shouldSkipAuditFunc: function(req, res){\n        // Custom logic here.. i.e: return res.statusCode === 200\n        return false;\n    }\n}));\n```\n\n[npm-image]: https://img.shields.io/npm/v/express-requests-logger.svg?style=flat\n[npm-url]: https://npmjs.org/package/express-requests-logger\n[travis-image]: https://travis-ci.org/PayU/express-request-logger.svg?branch=master\n[travis-url]: https://travis-ci.org/PayU/express-request-logger\n[coveralls-image]: https://coveralls.io/repos/github/PayU/express-request-logger/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/github/PayU/express-request-logger?branch=master\n[downloads-image]: http://img.shields.io/npm/dm/express-requests-logger.svg?style=flat\n[downloads-url]: https://npmjs.org/package/express-requests-logger\n[license-image]: https://img.shields.io/badge/License-Apache%202.0-blue.svg\n[license-url]: https://opensource.org/licenses/Apache-2.0\n[nsp-image]: https://nodesecurity.io/orgs/zooz/projects/ca2387c7-874c-4f5d-bd4e-0aa2874a1ae1/badge\n[nsp-url]: https://nodesecurity.io/orgs/zooz/projects/ca2387c7-874c-4f5d-bd4e-0aa2874a1ae1\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpayu%2Fexpress-request-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpayu%2Fexpress-request-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpayu%2Fexpress-request-logger/lists"}