1.0.0 • Published 7 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 tag
to trace messages with - Tracing is configured in a single place - config file
- Tracing configuration specifies transports to be used by a
tracing tag
for 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 --save
Resolving:
const tracer = require('winston-tracer');
tracer
object has the following API:
winston
- property that referenceswinston
moduleget(tag)
- returnswinston
logger for a giventracing tag
(i.e., label)configure(config)
- configureswinston
loggers
config
is an array of the following objects structure:
pattern
- regex to match tracing tagsgetOptions(tag)
- function that accepttracing tag
as the parameter and returnswinston
configuration 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
7 years ago