bunyan-logger-manager

0.1.5 • Public • Published

Bunyan Logger Manager

Express middleware to update the log level of your Bunyan loggers over REST

npm version npm js-standard-style Coverage Status Build Status

npm install bunyan-logger-manager

Example usage:
Include the module in your server.js and add it as middleware, passing in the loggers
IMPORTANT: the 'body-parser' package is required and should be added as middleware BEFORE this for this to work as expected*

// server.js
var bodyParser = require('body-parser')
var bunyanLoggerManager = require('bunyan-logger-manager')
 
var logger1 = bunyan.createLogger({
  name: "logger1",
  level: "INFO"
})
 
var logger2 = bunyan.createLogger({
  name: 'logger2',
  level: 'FATAL'
})
 
var app = express()
 
// bodyParser.json() must be used *before* this middleware
app.use(bodyParser.json())
app.use('/log-level', bunyanLoggerManager([logger1, logger2]))
 
app.listen(3000)

GET '/log-level' for the current loggers and levels:

[
  {
    "loggerName": "logger1",
    "level": "INFO"
  },
  {
    "loggerName": "logger2",
    "level": "FATAL"
  }
]

Update the log level using PUT to '/log-level':
Request body:

/* PUT request body */
[
  {
    "loggerName": "logger1",
    "level": "WARN"
  }
]

The response body will be the same as the request if the update completed successfully (with status 200 - OK)

/* 200 - OK */
[
  {
    "loggerName": "logger1",
    "level": "WARN"
  }
]

In the case of errors (e.g. invalid logger, logLevel), a 400 statusCode will be given with error messages:

/* 400 - Bad Request */
[
  {
    "loggerName": "logger1",
    "level": "WARN",
    "errors": [
      "Invalid log level of 'UNICORN' specified"
    ]
  }
]

Package Sidebar

Install

npm i bunyan-logger-manager

Weekly Downloads

184

Version

0.1.5

License

MIT

Last publish

Collaborators

  • mentalatom