Giter Club home page Giter Club logo

express-bunyan-logger's Introduction

Express-bunyan-logger

A express logger middleware powered by bunyan.

Build Status dependencies

Installation

npm install express-bunyan-logger

Usage

To use the logger:

app.use(require('express-bunyan-logger')());

To use the errorLogger:

app.use(require('express-bunyan-logger').errorLogger());

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

app.use(require('express-bunyan-logger')({
    name: 'logger', 
    streams: [{
        level: 'info',
        stream: process.stdout
        }]
    }));

Change default format:

app.use(require('express-bunyan-logger')({
    format: ":remote-address - :user-agent[major] custom logger"
});

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

app.use(require('express-bunyan-logger')();
app.use(function(req, res, next) {
    req.log.debug('this is debug in middleware');
    next();
});

Configuration

options.format

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

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

options.parseUA

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

options.levelFn

Function that translate statusCode into log level.

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

options.excludes

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

options.immediate

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

options.genReqId

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.
app.use(require('express-bunyan-logger')({
    genReqId: function(req) {
       return req.id;
    }
});

License

(The BSD License)

Copyright (c) 2013, Villa.Gao <[email protected]>;

express-bunyan-logger's People

Contributors

benjschneider avatar charlesfeng avatar gtracy avatar ognian avatar parisholley avatar sahat avatar simonexmachina avatar villadora avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.