loopback-component-bunyan

Bunyan logger component for loopback

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
loopback-component-bunyan
522.0.0a year ago6 years agoMinified + gzip package size for loopback-component-bunyan in KB

Readme

loopback-component-bunyan
Creates a Bunyan logger based on configuration in component-config.json file.
Here is a small example to illustrate:
{
	...
	"loopback-component-bunyan": {
		"level": "debug",
		"streams": [
			{
				"type": "prettystream",
			}
		]
	}
	...
}

The type property is one of the following supported stream types:

Unfortunately Bunyan does not support a stream registry the way Winston does, so for now this project will need to explicitly include the necessary streams.

Getting a Log object

The configuration above attaches a method app.logger which can be used to obtain a new logger for your module:
let log = app.logger('MyComponent');

log.debug({}, 'My log message');

requestLogger Middleware

The component comes with a request logging middleware. Bellow is an example of how it can be connected.
# middleware.json
{
	...
	"routes": {
		"loopback-component-bunyan#requestLogger": {
			"params": {
				"level": "info",
				"msg": "${res.statusCode} ${req.method} ${res.time}ms ${req.decodedUrl}",
				"meta": false
			}
		},
		...
	}
	...
}

Available options:
  • level String log level to report request
  • msg String message template
  • meta Boolean whether or not to include request/response meta information such as headers, body, query...