Service Logging
Does some logging bootstrapping with Bunyan and basic serializers and exposes Connect middleware to wire up logging in a service.
Usage
var express = require('express'), myStreams = require('./my-streams'), logging = require('service-logging')({ name: 'my-service', environment: 'dev', streams: myStreams }); var app = express();app.use(logging.attachLoggerToReq); // adds req.loggerapp.use(logging.logResponses);app.use(function(req, res, next) { req.thing = 'otherThing'; next();});app.use(logging.attachToLogger('thing')); // {thing: 'otherThing'} is now added to future req.logger callsapp.get('/', function(req, res) { res.send('Hello!');});app.use(logging.logErrors);
Configuration
The following options are exposed on the context:
environment
- A description of the environment (e.g., dev, staging)name
- The service's namestreams
- Bunyan streams to write to (takes an array, not a function)serializers
- (Optional) Additional Bunyan serializersversion
- (Optional) Version object to include in logs