stackdriver-logging-winston-koa

This module provides an Koa middleware for working with Stackdriver Logging,
compatible with Winston.
The implementation is adapted from the existing express middleware implementation
in nodejs-logging-winston module.
For general documentation on winston logging to Stackdriver please refer to the
nodejs-logging-winston module.
Quickstart
Installing the client library
npm install stackdriver-logging-winston-koa
Using the koa middleware
We provide a middleware that can be used in an koa application. Apart from
being easy to use, this enables some more powerful features of Stackdriver
Logging: request bundling. Any application logs emitted on behalf of a specific
request will be shown nested inside the request log.
The middleware adds a winston
-style log function to the ctx
object. You
can use this wherever you have access to the ctx
object. All log entries that
are made on behalf of a specific request are shown bundled together in the
Stackdriver Logging UI.
const lw = require('stackdriver-logging-winston-koa');
const winston = require('winston');
const koa = require('koa');
const logger = winston.createLogger();
async function startServer() {
const mw = await lw.koa.makeMiddleware(logger);
const app = koa();
app.use(mw);
app.use(async (ctx) => {
ctx.log.info('this is an info log message');
ctx.body = 'hello world';
});
logger.info('bonjour');
app.listen(8080, () => {
console.log('http server listening on port 8080');
});
}
startServer();
Contributing
Contributions welcome!
License
Apache Version 2.0