{"id":22271277,"url":"https://github.com/anishlushte07/request-logger","last_synced_at":"2025-03-25T15:51:58.851Z","repository":{"id":57231891,"uuid":"206786769","full_name":"AnishLushte07/request-logger","owner":"AnishLushte07","description":"Log request to database.","archived":false,"fork":false,"pushed_at":"2019-12-19T09:18:22.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T14:18:44.001Z","etag":null,"topics":["accesslog","request-logging","requests"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnishLushte07.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-06T12:14:26.000Z","updated_at":"2024-05-01T09:01:09.000Z","dependencies_parsed_at":"2022-09-26T16:32:04.025Z","dependency_job_id":null,"html_url":"https://github.com/AnishLushte07/request-logger","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnishLushte07%2Frequest-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnishLushte07%2Frequest-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnishLushte07%2Frequest-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnishLushte07%2Frequest-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnishLushte07","download_url":"https://codeload.github.com/AnishLushte07/request-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245495583,"owners_count":20624805,"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":["accesslog","request-logging","requests"],"created_at":"2024-12-03T12:11:27.901Z","updated_at":"2025-03-25T15:51:58.830Z","avatar_url":"https://github.com/AnishLushte07.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NodeJS Request Logger\nThis module creates a middleware for request logging. \nThis logs request url, status and response time to mysql database using sequelize on response finish event without affecting api performance.\nAdditional properties `user_id: req.user.id`\n\n## Prerequisites\nThis middleware need time taken by request to complete.\n- [Response Time](https://www.npmjs.com/package/response-time) `npm install --save response-time`\n\nMYSQL Table Schema (table name is configurable)\n\n```sql\nCREATE TABLE IF NOT EXISTS `access_logs` (\n  `id` int(11) NOT NULL,\n  `response_time` decimal(15,4) DEFAULT NULL,\n  `status` int(11) DEFAULT NULL,\n  `request` varchar(255) DEFAULT NULL,\n  `method` varchar(255) DEFAULT NULL,\n  `user_id` int(14) DEFAULT NULL,\n  `app_id` tinyint(3) unsigned DEFAULT NULL,\n  `created_on` datetime DEFAULT CURRENT_TIMESTAMP\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n\nALTER TABLE `access_logs`\n  ADD PRIMARY KEY (`id`);\n\nALTER TABLE `access_logs`\n  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;\n```\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-request-logging\n```\n\n## API\n```js\nconst requestLogger = require('express-request-logging')\n```\n\n### requestLogger(db, config, callback)\n\nCreate a middleware that logs request url, status and response time on response finish event.\n\n### db\nIts sequelize database instance in which `access_logs` table is present.\n\n### config\nYou can override default table name and pass application id.\n\n```\n {\n    appId: number, // this is used if multiple application storing request logs in same database (default: null)\n    tableName: string, // mysql table name (default: 'access_logs')\n }\n```\n\n### callback\n\nCallback will be called in case of any error\n\n## Example\n\n### Default\n\n```js\nconst responseTime = require('response-time')\nconst requestLogger = require('express-request-logging')\n\napp.use(responseTime())\napp.use(requestLogger(sequelizeInstance)\n```\n\n### Custom\n\n```js\nconst responseTime = require('response-time')\nconst requestLogger = require('express-request-logging')\n\napp.use(responseTime())\napp.use(requestLogger(sequelizeInstance, { appId: 1 }, (err) =\u003e console.log(err))\n\n```\n\n## License\n\n[MIT](LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanishlushte07%2Frequest-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanishlushte07%2Frequest-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanishlushte07%2Frequest-logger/lists"}