winston-meta-wrapper

1.2.0 • Public • Published

winston-meta-wrapper

Wraps winston logger instance to always add a set of metadata

This wrapper around winston loggers allows you to log a static or dynamic set of metadata with each log statement being executed without explicitely adding it as meta argument.

It also fixes the JSON string interpolation issue in winston

Installation

npm install winston-meta-wrapper

Usage

Wrapping Winston Logger to add static metadata

var winston = require('winston')
var winstonWrapper = require('winston-meta-wrapper')
 
var logger = new winston.Logger({
  transports: [
    new winston.transports.Console()
  ]
})
 
logger = winstonWrapper(logger)
 
logger.addMeta({
  test: 'Test Meta'
})
 
logger.info('test message')

Wrapping Winston Logger to add dynamic metadata

var winston = require('winston')
var winstonWrapper = require('winston-meta-wrapper')
 
var logger = new winston.Logger({
  transports: [
    new winston.transports.Console()
  ]
})
 
logger = winstonWrapper(logger)
 
logger.getMeta = function () {
  return {
    module: Math.random()
  }
}
 
logger.info('test message')
logger.info('test message')

Chaining wrapped Winston Loggers

var winston = require('winston')
var winstonWrapper = require('winston-meta-wrapper')
 
var logger = new winston.Logger({
  transports: [
    new winston.transports.Console()
  ]
})
 
logger = winstonWrapper(logger)
 
logger.addMeta({
  test: 'Test Meta'
})
 
logger = winstonWrapper(logger)
 
logger.addMeta({
  test2: 'Test 2 Meta'
})
 
logger.info('test message')

Package Sidebar

Install

npm i winston-meta-wrapper

Weekly Downloads

100

Version

1.2.0

License

MIT

Last publish

Collaborators

  • tdelaet