bunyan-buddy
v1.6.0
Published
Reduce the amount of Bunyan boilerplate code required, ideal when working with microservices.
Downloads
16
Readme
bunyan-buddy
Reduce the amount of Bunyan boilerplate code required with integration for Google Cloud Logging, ideal when working with microservices.
bunyan-buddy sets up a local stream using bunyan-prettystream (https://github.com/MaximusHaximus/node-bunyan-prettystrea) and a remote stream using @google-cloud/logging-bunyan. You can set the log levels for each using environment variables or as options when initializing it. For testing Google Cloud Logging locally, you can manually auth with it using a service account file.
Usage
const log = require('bunyan-buddy')(
app: {
name: 'my-app-name', // defaults to 'app'
version: '1.0.0', // defaults to undefined
},
local_level: 'debug', // defaults to process.env.LOG_LEVEL_LOCAL or 'info'
remote_level: 'info', // defaults to process.env.LOG_LEVEL_REMOTE or not set
// optionally auth with google cloud logging
// defaults to not set (auth is automatic if hosted on Google Cloud Platform)
remote_auth: {
projectId: 'my-google-cloud-project',
keyFilename: '/path/to/gcloud-auth.json',
},
});
log.info('This is logged locally and to Google Cloud Logging!');
log.debug('This is only logged locally (with the above options)');
log.error('This will log an error locally and on Google Cloud Logging, but not Google Cloud Error Reporting');
log.error(new Error('This will log in Google Cloud Error Reporting only if hosted on Google Cloud Platform'));