Router
Installation
$ npm install express-router-bunyan-loglevel
Usage
var createRouter = ;
createRouter( logger )
Returns an Express router configured to use a Bunyan logger.
var bunyan = ;var logger = bunyan;var router = ;
router
A mountable Express route handler.
var express = ;// Create a new application:var app = ;// Mount the route handler on the application:app;
Routes
PUT /loglevel
URI endpoint for setting the server application global log level.
Request: (application/json)
The request should include a JSON body having the following fields:
- level: log level. The level may be specified as either a
string
ornumber
. Thestring
may be one of the following (see node-bunyan;string
options listed along with their numeric equivalents):- (60) fatal
- (50) error
- (40) warn
- (30) info
- (20) debug
- (10) trace
"level": <string|number>
Response: 204 (text/plain)
The response body will be
OK
Error: 400 (application/json)
If a request contains invalid body parameters, an error response will contain the error status
and an associated message
.
"status": 400"message": "...'"
Examples
From the command-line,
$ curl -X PUT -d '{"level":"info"}' 'http://127.0.0.1:<port>/loglevel' --header "Content-type:application/json"
From another Node application,
var request = ;var body ='level': 'info';;{if errorconsole;return;console;}
A successful request will receive the following response body:
OK
PUT /loglevel/:name
URI endpoint for setting the log level for a log stream specified by the name
parameter.
Request: (application/json)
The request should include a JSON body having the following fields:
- level: log level. The level may be specified as either a
string
ornumber
. Thestring
may be one of the following (see node-bunyan;string
options listed along with their numeric equivalents):- (60) fatal
- (50) error
- (40) warn
- (30) info
- (20) debug
- (10) trace
"level": <string|number>
Response: 204 (text/plain)
The response body will be
OK
Error: 400 (application/json)
If a request contains invalid body parameters, an error response will contain the error status
and an associated message
.
"status": 400"message": "...'"
Examples
From the command-line,
$ curl -X PUT -d '{"level":"info"}' 'http://127.0.0.1:<port>/loglevel/<name>' --header "Content-type:application/json"
From another Node application,
var request = ;var body ='level': 'info';;{if errorconsole;return;console;}
A successful request will receive the following response body:
OK
Examples
var bunyan =request =express =createRouter = ;// LOGGER //var logger = bunyan;// APP //var app = ;// Mount the router on the application:app;// Create an HTTP server:app;{logger;;}// RUN //{;;;}{;}{;}{if errorthrow error;console;}{process;}
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. Athan Reines.