node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org »



A 0mq transport for winston.


Installing npm (node package manager)

  $ curl | sh

Installing winston-zmq

  $ npm install winston
  $ npm install winston-zmq


This winston transport allows you to publish logs using a 0mq pub socket (so that multiple recipients can subscribe to it)

The message is sent with a variable length prefix that allows the subscribers to subscribe log message of a certain threshold and above.


  var winston = require('winston');
  // Requiring `winston-zmq` will expose 
  // `winston.transports.Zmq` 
  winston.add(winston.transports.Zmq, options);

The Zmq transport takes the following options. 'db' is required:

  • transport: Transport to use for 0mq. (tcp|ipc|inproc|pgm|epgm)
  • address: Address that the socket will bind to e.g. "" or ""
  • separator: Separator to separate the level string from the JSON default |*|
  • prefix: Prefix used to denote the log level
  • prefixMapping: Mapping between log levels and prefix string length. Used if using custom log levels. e.g. { silly: 1, verbose: 2, info: 3, warn: 4, debug: 5, error: 6 }
  • port: [required for tcp] : port to bind to when using the tcp transport
  • level: Level of messages that this transport should log.
  • silent: Boolean flag indicating whether to suppress output.
  • formatter: Optional formatter function to override the structure of the JSON data sent to the subscriber

Metadata: Logged as a native JSON object.



var util = require('util'), zmq = require('zmq');
var socket = zmq.socket('sub');
socket.subscribe(''); // subscribe to all
// socket.subscribe('***'); // subscribe to info and above
socket.on('message', function(bufMsg) {
    var msg = bufMsg.toString('utf8');
    try {
        var message = msg.split('|*|')[1];
        oMessage = JSON.parse(message);
    } catch(err) {

Log Source

var winston = require('winston');
var Zmq = require('../lib/winston-zmq.js').Zmq;
var transports = {};
// Set up the zmq transport
transports.Zmq = new Zmq({level : 'silly',port: 7890});
// Instantiate out logger.
var logger = new (winston.Logger)({transports : [transports.Zmq]});
logger.log('silly', 'Some Text', {somekey: 'some data'});
logger.log('error', 'Some Text', {somekey: 'some data'});

Message Format

The above two messages will be transmitted as:

*|*|{"timestamp":"2011-11-16T15:53:55.912Z","level":"silly","message":"Some Text","meta":{"somekey":"some data"}}
******|*|{"timestamp":"2011-11-16T15:53:55.913Z","level":"error","message":"Some Text","meta":{"somekey":"some data"}}

Author: David Henderson