1.0.0 • Published 9 years ago
winston-tracer v1.0.0
The package is inspired by ASP.NET tracing API. The main ideas are:
- Each component/module acquires a
tracing tagto trace messages with - Tracing is configured in a single place - config file
- Tracing configuration specifies transports to be used by a
tracing tagfor a given log level
I found it's a little clumsy to do with winston, so I created a wrapper that helps me to archive what I need.
Installation:
npm install winston-tracer --saveResolving:
const tracer = require('winston-tracer');tracer object has the following API:
winston- property that referenceswinstonmoduleget(tag)- returnswinstonlogger for a giventracing tag(i.e., label)configure(config)- configureswinstonloggers
config is an array of the following objects structure:
pattern- regex to match tracing tagsgetOptions(tag)- function that accepttracing tagas the parameter and returnswinstonconfiguration object
Below is example of how to use that.
Tracing is configured on an app start up:
// get tracer
const tracer = require('winston-tracer');
// tracer configuration that enables verbose logging for all tracing tags
tracer.configure([
{
pattern: '.*',
getOptions (tag) {
return {
level: 'verbose',
transports: [new (tracer.winston.transports.Console)({
label: tag, // that is important to let winston know about tracing tag
colorize: true,
prettyPrint: true,
timestamp: true
})]
};
}
}
]);Loggers are used in the following way, for example, in server.js:
const logger = require('winston-tracer').get('server');
logger.verbose('Starting to serve on', server.info.uri);1.0.0
9 years ago