json-log.express

2.0.0 • Public • Published

json-log.express

A json log middleware for express. Powered by bunyan.

Installation

npm install json-log.express

Usage

At first, set your NODE_ENV

  • production: JSON log output
  • others: Standard Apache combined log output

To use the requestLogger, place it in the front of all middlewares:

const jsonlog = require('json-log.express')()
app.use(jsonlog.requestLogger)

To use the errorLogger, place it in the front of last error handler middleware:

const jsonlog = require('json-log.express')()
app.use(jsonlog.errorLogger)

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

const jsonlog = require('json-log.express')()
app.use(jsonlog.requestLogger)
 
app.use(function(req, res, next) {
  req.log.debug('this is debug in middleware')
  next()
})

Configuration

opts.name

The name of logger. Default is anonymous application.

opts.level

The level of logger. Default is trace.

opts.hidden

The fields to be hidden.

opts.levelFn

Function that translate statusCode into log level.

License

MIT

Package Sidebar

Install

npm i json-log.express

Weekly Downloads

1

Version

2.0.0

License

MIT

Last publish

Collaborators

  • m31271n_account