{"id":15097852,"url":"https://github.com/kasa-network/koa-logging","last_synced_at":"2025-10-08T02:31:55.580Z","repository":{"id":57124025,"uuid":"155594982","full_name":"kasa-network/koa-logging","owner":"kasa-network","description":"🌲 Koa Logging Middleware with Pino","archived":true,"fork":false,"pushed_at":"2020-06-03T19:51:50.000Z","size":17,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-11-16T16:30:14.230Z","etag":null,"topics":["koa","koa-middleware","koa2","koa2-middleware","logging","logging-library","node-log","pino","pino-logs"],"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/kasa-network.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}},"created_at":"2018-10-31T17:08:13.000Z","updated_at":"2023-01-28T08:58:08.000Z","dependencies_parsed_at":"2022-08-25T15:25:23.310Z","dependency_job_id":null,"html_url":"https://github.com/kasa-network/koa-logging","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasa-network%2Fkoa-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasa-network%2Fkoa-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasa-network%2Fkoa-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasa-network%2Fkoa-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kasa-network","download_url":"https://codeload.github.com/kasa-network/koa-logging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235674061,"owners_count":19027515,"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":["koa","koa-middleware","koa2","koa2-middleware","logging","logging-library","node-log","pino","pino-logs"],"created_at":"2024-09-25T16:40:55.086Z","updated_at":"2025-10-08T02:31:50.291Z","avatar_url":"https://github.com/kasa-network.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e@kasa/koa-logging\u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  A middleware that logs request and response in Koa\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://circleci.com/gh/kasa-network/koa-logging\"\u003e\n    \u003cimg alt=\"CircleCI\" src=\"https://circleci.com/gh/kasa-network/koa-logging.svg?style=shield\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/kasa-network/koa-logging\"\u003e\n    \u003cimg src=\"https://coveralls.io/repos/github/kasa-network/koa-logging/badge.svg\" alt='Coverage Status' /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://badge.fury.io/js/@kasa/koa-logging\"\u003e\n    \u003cimg alt=\"npm version\" src=\"https://img.shields.io/npm/v/@kasa/koa-logging.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://david-dm.org/kasa-network/koa-logging\"\u003e\n    \u003cimg alt=\"npm\" src=\"https://img.shields.io/david/kasa-network/koa-logging.svg?style=flat-square\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/mit-license.php\"\u003e\n    \u003cimg alt=\"MIT Licence\" src=\"https://badges.frapsoft.com/os/mit/mit.svg?v=103\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/ellerbrock/open-source-badge/\"\u003e\n    \u003cimg alt=\"Open Source Love\" src=\"https://badges.frapsoft.com/os/v1/open-source.svg?v=103\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\n## Installation\n\n```bash\n# Using NPM\n$ npm install --save @kasa/koa-logging\n# Using Yarn\n$ yarn add @kasa/koa-logging\n```\n\n### Dependencies\n\n- [**Koa**](https://github.com/koajs/koa) 2.0+\n- [**Node.js**](https://nodejs.org) 8.0.0+\n\n\n## Usage\n\nUse `koa-request-id` as a middleware for a [koa](https://github.com/koajs/koa) app. By default, it writes logs into `stdin` for HTTP requests, responses and errors. Every log include the request id, which logger will try to get from common places such as `ctx.reqId`, `ctx.state.reqId`, `ctx.req.id`.\n\nIn the following example, you can check the request and response logs from `stdin`:\n\n```js\n// app.js\nconst Koa = require('koa');\nconst requestId = require('@kasa/koa-request-id');\nconst logging = require('@kasa/koa-logging');\nconst pino = require('pino');\nconst app = new Koa();\n\napp.use(requestId());\napp.use(logging({ logger: pino() }));\napp.use(async ctx =\u003e {\n  ctx.body = 'Hello, logging!';\n});\n\napp.listen(3000);\n```\n\n```bash\n$ node app.js || pino-pretty -c -l -t\n```\n\n```bash\n$ curl -X POST http://localhost:3000/users\n```\n\n```bash\nINFO [2018-11-04 09:54:00.596 +0000] (app/15600 on my-macbook): POST /users (4f83e15b-c34c-4f8c-9f57-938e54e54ae3)\n    reqId: \"4f83e15b-c34c-4f8c-9f57-938e54e54ae3\"\n    req: {\n      \"method\": \"POST\",\n      \"path\": \"/users\",\n      \"url\": \"/users\",\n      \"headers\": {\n        \"host\": \"localhost:3000\",\n        \"user-agent\": \"curl/7.54.0\",\n        \"accept\": \"*/*\"\n      },\n      \"protocol\": \"http\",\n      \"ip\": \"127.0.0.1\",\n      \"query\": {}\n    }\n    event: \"request\"\n```\n\n\n## API\n\n### Creating an middleware\n\nYou can create a new logging middleware by passing the existing pino logger and the relevant options to `logging`;\n\n```node\nconst logger = pino();\nconst middleware = logging({\n  logger,\n  serializers: {},\n  overrideSerializers: true,\n  getReqId: (ctx) =\u003e ctx.reqId,\n  getRequestLogLevel: (ctx) =\u003e 'info',\n  getResponseLogLevel: (ctx) =\u003e ctx.state \u003e= 500 ? 'error' : 'info',\n  getErrorLogLevel: (err) =\u003e 'error'\n});\n```\n\n### Middleware Configuration\n\nThese are the available config options for the middleware. All is optional except `logger`.\n\n```node\n{\n  // Logger instance of pino\n  logger: pino(),\n\n  // Serializers to override defaults provided\n  serializers: {\n    req: (ctx) =\u003e ({\n      ...\n    }),\n    user: (ctx) =\u003e ({\n      ...\n    })\n  },\n\n  // Ovveride serializers if true (default: true)\n  overrideSerializers: true,\n\n  // Function to get the request id from `ctx`\n  getReqId: (ctx) =\u003e ctx.reqId,\n\n  // Function to decide log level of the request from `ctx`\n  getRequestLogLevel: (ctx) =\u003e 'info',\n\n  // Function to decide log level of the response from `ctx`\n  getResponseLogLevel: (ctx) =\u003e ctx.state \u003e= 500 ? 'error' : 'info',\n\n  // Function to decide log level of the error from `err`\n  getErrorLogLevel: (err) =\u003e 'error'\n}\n```\n\n\n## Contributing\n\n#### Bug Reports \u0026 Feature Requests\n\nPlease use the [issue tracker](https://github.com/kasa-network/koa-logging/issues) to report any bugs or ask feature requests.\n\n\n## License\n\nCopyright © 2018, [Kasa](http://www.kasa.network).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasa-network%2Fkoa-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkasa-network%2Fkoa-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasa-network%2Fkoa-logging/lists"}