@abbit/bunyan-cloud-function

A Raw Stream plugin so you can use Bunyan with StackDriver by ajusting the format you print to stdout(no network or async shenanigans).

Usage no npm install needed!

<script type="module">
  import abbitBunyanCloudFunction from 'https://cdn.skypack.dev/@abbit/bunyan-cloud-function';
</script>

README

bunyan-cloud-function

A package that allows you to use Bunyan on Google Cloud Functions, have your logs appear on StackDriver, and not have to deal with missing logs, async log saving, delayed logs due to function freeze after return, etc, etc, etc.

Install

npm i --save @abbit/bunyan-cloud-function

Usage

import bunyan from 'bunyan';
import {LoggingBunyan} from '@abbit/bunyan-cloud-function';

const loggingBunyan = new LoggingBunyan();

const logger = bunyan.createLogger({
    name: 'test',
    streams: [
        loggingBunyan.stream('INFO') // Will log to stdout in a format that stackdriver understands
    ],
});

Tech stuff

This package changes the json format written to stdout(yes, stdout) just enough so that StackDriver recognizes the messages and log levels.

We created this because we like Bunyan and all other solutions were a pain to use. The file is 100 lines long so if it's not quite right for you feel free to play around and submit a pull request.