Socket
Book a DemoInstallSign in
Socket

winston-nanomsg

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

winston-nanomsg

A Nanomsg transport for Winston

0.0.4
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

winston-nanomsg

A nanomsg transport for winston.

Installation

Installing winston-nanomsg

  $ npm install winston-nanomsg

Purpose

This winston transport allows you to publish logs using a nanomsg 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.

Usage

  var winston = require('winston');  
  require('winston-nanomsg');  
  winston.add(winston.transports.Nanomsg, options);

The Nanomsg transport takes the following options.

  • transport: Transport to use for Nanomsg. (inproc|ipc|tcp)
  • address: Address that the socket will bind to e.g. "127.0.0.1" or "*" or "eth0"
  • 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.
  • formatter: Optional formatter function to override the structure of the JSON data sent to the subscriber

Metadata: Logged as a native JSON object.

Examples

Client

'use strict';

let nano = require('nanomsg');
// subscribe to all log levels
let sub = nano.socket('sub', {chan:['']});

sub.on('data', function(buffer) {
  try {
    let msg = String(buffer).split('|*|')[1];
    console.log(JSON.parse(msg));
  } catch(error) {
    console.log(error);
  }
});

sub.connect('tcp://127.0.0.1:5678');

Log Source

'use strict';

var winston = require('winston');
require('winston-nanomsg');

let logger = new (winston.Logger)({
  transports: [
    new (winston.transports.Nanomsg)({
      address:'127.0.0.1',
      port: 5678,
      level: 'silly'
    })
  ]
});

let seq = 0;

setInterval(function() {
  logger.log('info', 'foo:' + seq);
  logger.log('debug', 'bar:' + seq);
  ++seq;
}, 1000);

Message Format

The above two messages will be transmitted as:

***|*|{"timestamp":"2015-09-22T14:25:37.936Z","level":"info","message":"foo:0","meta":{}}
*****|*|{"timestamp":"2015-09-22T14:25:37.943Z","level":"debug","message":"bar:0","meta":{}}

Author: Maxim Tsyplakov

Keywords

logger

FAQs

Package last updated on 31 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.