Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

winston-cluster

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

winston-cluster

Winston transport for clustered services

  • 0.5.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
92
increased by12.2%
Maintainers
2
Weekly downloads
 
Created
Source

winston-cluster

NPM Version Build Status Dependency Status

Winston transport for Node.js clustering.
Uses IPC to send log information from cluster workers to the master process for file based or other single threaded logging.

Usage

#!/usr/bin/env node

var cluster = require('cluster');
var winston = require('winston');
var winstonCluster = require('./lib/winston-cluster');

var logLevel = 'info';

if (cluster.isMaster) {

    // Create parent thread logger
    // Other transports (ie. file writing) should be bound to this
    var logger = new winston.Logger({
        transports: [
            new winston.transports.Console({
                level: logLevel,
            }),
        ]
    });

    // Start child threads
    var cpuCount = require('os').cpus().length;
    for (var i = 0; i < cpuCount; i++) {
        cluster.fork();
    }

    // Bind event listeners to child threads using the local logger instance
    // has to be called after the child threads are started.
    winstonCluster.bindListeners(logger);

    // Logging works as normal in the main thread
    logger.info("Started server!")

    // Server thread logic here
    // ...

} else {

    // Create a new logger instance for the child thread using the cluster transport to
    // send data back to the parent thread.
    // Note that log level must also be set here to avoid filtering prior to sending logs back
    var logger = winston.createLogger({transports: [
        new winstonCluster({
            level: logLevel,
        }),
    ]})

    // Logging in this instance now passed via IPC back to the parent
    // (and tagged with the worker thread ID)
    logger.info("Test Message!")

    // Client thread logic here
    // ...

}

Binding Multiple Logger Instances

See example-multi-logger.js for an example on binding multiple logger instances.

TODO

  • Write tests (check message passing works between threads)
  • Refactor names of messages structures (maybe add a prototype)
  • Allow bypass for other callbacks on non log messages

Keywords

FAQs

Package last updated on 19 Oct 2020

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc