good-winston
v4.0.0
Published
hapi good-reporter to winston logging adapter
Downloads
6,967
Maintainers
Readme
good-winston
A hapi good stream to winston logging adapter.
This stream clones good-console but terminates logs to winston.
Installation
$ npm install -S winston
$ npm install -S good-winston
Usage
To use the GoodWinston
you simply need to require it and pass it a winston logger instance -
const GoodWinston = require('good-winston');
const winston = require('winston');
const goodWinstonStream = new GoodWinston({ winston });
The following config
options are availble to configure GoodWinston
:
config
- required configuration object with the following keyswinston
- winston logger (required).level
- Log level for internal events -error
- Map all gooderror
events to this winston level (Defaulterror
).other
- Map all other good events to this winston level (Defaultinfo
).ops
- Map all goodops
events to this winston level (Defaultinfo
).response
- Map all goodresponse
events to this winston level (Defaultinfo
).request
- Map all goodrequest
events to this winston level (Defaultundefined
so level will be deduced from tags).
format
- MomentJS format string. Defaults to 'YYMMDD/HHmmss.SSS'.utc
- boolean controlling Moment using utc mode or not. Defaults totrue
.color
- a boolean specifying whether to output in color. Defaults totrue
.
Integrating with good
As with any good stream new good-winston
you can either pass the created stream to good -
const GoodWinston = require('good-winston');
const goodWinstonStream = new GoodWinston({ winston: require('winston') });
const good = require('good');
server.register({
register: good,
options: {
reporters:{
winston: [ goodWinstonStream ]
}
}, err => {
if (err) {
throw err;
}
});
Or you can have good initiate the stream from the module for you -
const winston = require('winston');
const good = require('good');
server.register({
register: good,
options: {
reporters:{
winston: [{
module: 'good-winston',
args: [{ winston }]
}]
}
}, err => {
if (err) {
throw err;
}
});
Using Tags and Levels
Using the level
parameter in the config
variable you can set the log level for internal events that are not controlled from your code (like ops
and response
) but for logs where are called from your code you should set a tag with the appropriate log level .good-winston
will iterate the tag and will set the level by the first tag that matches the winston
logger available levels. If no appropriate level was found other
level will be used