good-bunyan-gcloud-formatters
v1.0.6
Published
formatters for good-bunyan to enable Stackdriver to process structured logs
Downloads
117
Readme
good-bunyan-gcloud-formatters
formatters for good-bunyan to enable Stackdriver to process structured logs
Inspiration
Based on the default good-bunyan
formatters,
but extended to include the proper format
for Stackdriver's processing of structured
logs.
Usage
Intended for use with good-bunyan and @google-cloud/logging-bunyan.
Installation
$ npm install good-bunyan good-bunyan-gcloud-formatters @google-cloud/logging-bunyan --save
Configuration using good
import hapi from 'hapi';
import bunyan from 'bunyan';
import {LoggingBunyan} from '@google-cloud/logging-bunyan';
import * as formatters from 'good-bunyan-gcloud-formatters';
const stackDriver = new LoggingBunyan({
logName: 'flex_request_log'
});
const server = new hapi.server();
await server.register({
plugin: require('good'),
options: {
ops: {interval: 1000},
reporters: {
bunyan: [{
module: 'good-bunyan',
args: [
{log: '*', request: '*', response: '*', error: '*'},
{
logger: bunyan.createLogger({
name: 'logger',
streams: ['production' === process.env.NODE_ENV ? stackDriver.stream('trace') : {stream: process.stdout}]
}),
levels: {
response: 'info',
request: 'info'
},
formatters
}
]
}]
}
}
});
await server.start();
Contributing
Dependencies
$ nvm install
$ npm install
Verification
$ npm test