winston-cluster
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 nodevar cluster = ;var winston = ;var winstonCluster = ;var logLevel = 'info';if clusterisMaster// Create parent thread logger// Other transports (ie. file writing) should be bound to thisvar logger =transports:level: logLevel;// Start child threadsvar cpuCount = length;for var i = 0; i < cpuCount; i++cluster;// Bind event listeners to child threads using the local logger instance// has to be called after the child threads are started.winstonCluster;// Logging works as normal in the main threadlogger// 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 backvar logger = winston// Logging in this instance now passed via IPC back to the parent// (and tagged with the worker thread ID)logger// 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