stackdriver-logging-bunyan-koa
This module provides an Koa middleware for working with Stackdriver Logging, compatible with Bunyan.
The implementation is adopted from the exsting express middleware implementation in nodejs-logging-bunyan module.
For general documentation on bunyan logging to Stackdriver please refer to the nodejs-logging-bunyan module.
Quickstart
Installing the client library
npm install stackdriver-logging-bunyan-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 bunyan
-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 lb = ; // Import koa module and create an http server.const koa = ; { const logger mw = await lbkoa; const app = ; // Install the logging middleware. This ensures that a Bunyan-style `log` // function is available on the `context` object. Attach this as one of the // earliest middleware to make sure that log function is available in all the // subsequent middleware and routes. app; // Setup an http route and a route handler. app; // `logger` can be used as a global logger, one not correlated to any specific // request. logger; // Start listening on the http server. app;} ;
Contributing
Contributions welcome!
License
Apache Version 2.0