npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

niu-express-bunyan-logger

v0.1.4

Published

a bunyan logger middleware for niu

Downloads

1

Readme

Express-bunyan-logger

A express logger middleware powered by bunyan.

Build Status dependencies

Note

This year as work content change, I have no spare time to maintaining the node modules, if anyone want to take or keep maintaining, just contact me via [email protected] with Title contains: "Wanted: npm package xxxx". Thx.

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. The meta argument is an object consisting of all the fields gathered by bunyan-express-logger, before exclusions are applied.

function(status, err /* only will work in error logger */, meta) {
     // return string of level
     if (meta["response-time"] > 30000) {
         return "fatal";
     } else {
         return "info";
     }
}

options.includesFn

Function that is passed req and res, and returns an object whose properties will be added to the meta object passed to bunyan

function(req, res) {
    if (req.user) {
        return {
            _id: req.user._id,
            name: req.user.name
        }
    }
}

options.excludes

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

options.obfuscate

Array of strings to obfuscate. These strings can be in dotted notation, for instance body.password, and it will only replace that specific value. This will replace the values in log messages with a placeholder.

options.obfuscatePlaceholder

Placeholder to use when obfuscating values. This is only applicable when there are values to obfuscate. Default is [HIDDEN].

options.serializers

An object of bunyan serializers. They are passed on to bunyan. The default serializers are defined as follows:

{
    req: bunyan.stdSerializers.req,
    res: bunyan.stdSerializers.res,
    err: bunyan.stdSerializers.err
}

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]>;