# stackdriver-logging-bunyan-koa

> Koa middleware for Bunyan stream to Stackdriver Logging

Latest version **1.0.1** (published 2020-04-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install stackdriver-logging-bunyan-koa
pnpm add stackdriver-logging-bunyan-koa
yarn add stackdriver-logging-bunyan-koa
bun add stackdriver-logging-bunyan-koa
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-04-07 |
| First published | 2019-08-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.10.0 |
| Dependencies | 15 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tobias Binna |
| Maintainers | tbinna |
| Keywords | google apis client, google api client, google apis, google api, google, google cloud platform, google cloud, cloud, google logging, logging, stackdriver logging, stackdriver, bunyan stream, koa |

## Links

- npm: https://www.npmjs.com/package/stackdriver-logging-bunyan-koa
- Repository: https://github.com/toolsplus/stackdriver-logging-bunyan-koa
- Homepage: https://github.com/toolsplus/stackdriver-logging-bunyan-koa#readme
- Issues: https://github.com/toolsplus/stackdriver-logging-bunyan-koa/issues
- npm.io page: https://npm.io/package/stackdriver-logging-bunyan-koa

## Dependencies (15)

- [nyc](https://npm.io/package/nyc.md) ^14.1.1
- [snyk](https://npm.io/package/snyk.md) ^1.305.0
- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [delay](https://npm.io/package/delay.md) ^4.3.0
- [mocha](https://npm.io/package/mocha.md) ^6.2.3
- [bunyan](https://npm.io/package/bunyan.md) ^1.8.12
- [codecov](https://npm.io/package/codecov.md) ^3.5.0
- [proxyquire](https://npm.io/package/proxyquire.md) ^2.1.3
- [@types/uuid](https://npm.io/package/@types/uuid.md) ^3.4.5
- [@types/mocha](https://npm.io/package/@types/mocha.md) ^5.2.7
- [power-assert](https://npm.io/package/power-assert.md) ^1.6.1
- [@types/proxyquire](https://npm.io/package/@types/proxyquire.md) ^1.3.28
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.13
- [intelli-espower-loader](https://npm.io/package/intelli-espower-loader.md) ^1.0.1
- [@google-cloud/logging-bunyan](https://npm.io/package/@google-cloud/logging-bunyan.md) ^1.2.2

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-04-07
- 1.0.0-alpha.0 (alpha) — 2019-08-19
- 1.0.0 — 2019-08-20

## README

# stackdriver-logging-bunyan-koa

[![Build Status](https://travis-ci.org/toolsplus/stackdriver-logging-bunyan-koa.svg?branch=master)](https://travis-ci.org/toolsplus/stackdriver-logging-bunyan-koa)
[![npm version](https://badge.fury.io/js/stackdriver-logging-bunyan-koa.svg)](https://badge.fury.io/js/stackdriver-logging-bunyan-koa)
[![codecov](https://codecov.io/gh/toolsplus/stackdriver-logging-bunyan-koa/branch/master/graph/badge.svg)](https://codecov.io/gh/toolsplus/stackdriver-logging-bunyan-koa)

This module provides an [Koa](https://koajs.com) middleware for working with [Stackdriver Logging](https://cloud.google.com/logging/docs),
compatible with [Bunyan](https://www.npmjs.com/package/bunyan).

The implementation is adopted from the exsting express middleware implementation
in [nodejs-logging-bunyan](https://github.com/googleapis/nodejs-logging-bunyan) module.

For general documentation on bunyan logging to Stackdriver please refer to the
[nodejs-logging-bunyan](https://github.com/googleapis/nodejs-logging-bunyan) module.



## Quickstart

### Installing the client library

```bash
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.

```javascript
const lb = require('stackdriver-logging-bunyan-koa');

// Import koa module and create an http server.
const koa = require('koa');

async function startServer() {
  const {logger, mw} = await lb.koa.middleware();
  const app = koa();

  // 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.use(mw);

  // Setup an http route and a route handler.
  app.use(async (ctx) => {
    // `ctx.log` can be used as a bunyan style log method. All logs generated
    // using `ctx.log` use the current request context. That is, all logs
    // corresponding to a specific request will be bundled in the Stackdriver
    // UI.
    ctx.log.info('this is an info log message');
    ctx.body = 'hello world';
  });

  // `logger` can be used as a global logger, one not correlated to any specific
  // request.
  logger.info({port: 8080}, 'bonjour');

  // Start listening on the http server.
  app.listen(8080, () => {
    console.log('http server listening on port 8080');
  });
}

startServer();
```

## Contributing

Contributions welcome!

## License

Apache Version 2.0

---
_Source: https://npm.io/package/stackdriver-logging-bunyan-koa · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
