a bunyan logger middleware for express


A express logger middleware powered by bunyan.

npm install express-bunyan-logger

To use the logger:


To use the errorLogger:


And you can also pass bunyan logger options to the logger middleware:

    name: 'logger', 
    streams: [{
        level: 'info',
        stream: process.stdout

Change default format:

    format: ":remote-address - :user-agent[major] custom logger"

And a child logger will be attached to each request object:

app.use(function(reqresnext) {
    req.log.debug('this is debug in middleware');

Format string, please go the source code to the metadata. ":name" will print out; ":name[key]" will print out the property 'key' of

Or you can pass a function to options.format. This function accept a object as argument and return string.

Whether to parse user-agent in logger, default is =true=.

Function that translate statusCode into log level.

function(status, err /* only will work in error logger */) {
     // return string of level
     return "info";

Array of string, Those fields will be excluded from meta object which passed to bunyan

Write log line on request instead of response (for response times)

By default, express-bunyan-logger will generate an unique id for each request, and a field 'req_id' will be added to child logger in request object.

If you have already use other middleware/framework to generate request id, you can pass a function to retrieve it:

// suppose connect-requestid middleware is already added. 
    genReqIdfunction(req) {

(The BSD License)

Copyright (c) 2013, Villa.Gao <>;