{"id":21590974,"url":"https://github.com/toolsplus/stackdriver-logging-winston-koa","last_synced_at":"2026-03-08T11:35:44.724Z","repository":{"id":38173217,"uuid":"258431831","full_name":"toolsplus/stackdriver-logging-winston-koa","owner":"toolsplus","description":"Koa middleware for Winston transport to Stackdriver Logging","archived":false,"fork":false,"pushed_at":"2025-03-11T11:17:39.000Z","size":2294,"stargazers_count":1,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T11:26:06.928Z","etag":null,"topics":["koa","logging","stackdriver","winston"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/toolsplus.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-24T06:56:09.000Z","updated_at":"2025-03-11T11:17:14.000Z","dependencies_parsed_at":"2024-11-24T16:21:37.832Z","dependency_job_id":"9c33a38f-af9b-4cfd-b3e8-588e05e9b9d9","html_url":"https://github.com/toolsplus/stackdriver-logging-winston-koa","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.46153846153846156","last_synced_commit":"eb8be19fa91540df52d4f87f0add2257b868e376"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolsplus%2Fstackdriver-logging-winston-koa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolsplus%2Fstackdriver-logging-winston-koa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolsplus%2Fstackdriver-logging-winston-koa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolsplus%2Fstackdriver-logging-winston-koa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toolsplus","download_url":"https://codeload.github.com/toolsplus/stackdriver-logging-winston-koa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244198406,"owners_count":20414443,"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","logging","stackdriver","winston"],"created_at":"2024-11-24T16:21:27.168Z","updated_at":"2026-03-08T11:35:44.706Z","avatar_url":"https://github.com/toolsplus.png","language":"TypeScript","readme":"# stackdriver-logging-winston-koa\n\n![Build status](https://github.com/toolsplus/stackdriver-logging-winston-koa/actions/workflows/ci.yaml/badge.svg)\n[![npm version](https://badge.fury.io/js/stackdriver-logging-winston-koa.svg)](https://badge.fury.io/js/stackdriver-logging-winston-koa)\n[![codecov](https://codecov.io/gh/toolsplus/stackdriver-logging-winston-koa/branch/master/graph/badge.svg)](https://codecov.io/gh/toolsplus/stackdriver-logging-winston-koa)\n\nThis module provides an [Koa](https://koajs.com) middleware for working with [Stackdriver Logging](https://cloud.google.com/logging/docs),\ncompatible with [Winston](https://www.npmjs.com/package/winston).\n\nThe implementation is adapted from the existing express middleware implementation\nin [nodejs-logging-winston](https://github.com/googleapis/nodejs-logging-winston) module.\n\nFor general documentation on winston logging to Stackdriver please refer to the\n[nodejs-logging-winston](https://github.com/googleapis/nodejs-logging-winston) module.\n\n\n\n## Quickstart\n\n### Installing the client library\n\n```bash\nnpm install stackdriver-logging-winston-koa\n```\n\n\n### Using the koa middleware\n\nWe provide a middleware that can be used in an koa application. Apart from\nbeing easy to use, this enables some more powerful features of Stackdriver\nLogging: request bundling. Any application logs emitted on behalf of a specific\nrequest will be shown nested inside the request log.\n\nThe middleware adds a `winston`-style log function to the `ctx` object. You\ncan use this wherever you have access to the `ctx` object. All log entries that \nare made on behalf of a specific request are shown bundled together in the \nStackdriver Logging UI.\n\n```javascript\nconst lw = require('stackdriver-logging-winston-koa');\nconst winston = require('winston');\n\n// Import koa module and create an http server.\nconst koa = require('koa');\nconst logger = winston.createLogger();\n\nasync function startServer() {\n  // Create a middleware that will use the provided logger.\n  // A Stackdriver Logging transport will be created automatically\n  // and added onto the provided logger.\n  const mw = await lw.koa.makeMiddleware(logger);\n  // Alternatively, you can construct a LoggingWinston transport\n  // yourself and pass it int.\n  // const transport = new LoggingWinston({...});\n  // const mw = await lw.koa.makeMiddleware(logger, transport);\n  const app = koa();\n\n  // Install the logging middleware. This ensures that a Winston-style `log`\n  // function is available on the `context` object. Attach this as one of the\n  // earliest middleware to make sure that log function is available in all the\n  // subsequent middleware and routes.\n  app.use(mw);\n\n  // Setup an http route and a route handler.\n  app.use(async (ctx) =\u003e {\n    // `ctx.log` can be used as a winston style log method. All logs generated\n    // using `ctx.log` use the current request context. That is, all logs\n    // corresponding to a specific request will be bundled in the Stackdriver\n    // UI.\n    ctx.log.info('this is an info log message');\n    ctx.body = 'hello world';\n  });\n\n  // `logger` can be used as a global logger, one not correlated to any specific\n  // request.\n  logger.info('bonjour');\n\n  // Start listening on the http server.\n  app.listen(8080, () =\u003e {\n    console.log('http server listening on port 8080');\n  });\n}\n\nstartServer();\n```\n\n## Contributing\n\nContributions welcome!\n\n## License\n\nApache Version 2.0\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolsplus%2Fstackdriver-logging-winston-koa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoolsplus%2Fstackdriver-logging-winston-koa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolsplus%2Fstackdriver-logging-winston-koa/lists"}