forked from log4js-node/log4js-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Multiprocess
nomiddlename edited this page Jul 3, 2012
·
2 revisions
The multiprocess appender was added to log4js by dbrain. This allows multiple worker processes to log through a single master process, avoiding issues with rolling etc. in a clustered environment.
This was mainly created for cluster, but you can adapt the example to match your needs, you know, if it fits them.
// log4js-master.json ####
// Will listen for connections on port and host
{
"appenders": [{
"type": "logLevelFilter",
"level": "DEBUG",
"appender": {
"type": "multiprocess",
"mode": "master",
"loggerPort": 5001,
"loggerHost": "simonsaysdie",
"appender": {
"type": "file",
"filename": "muffin.log",
"maxLogSize": 104857600,
"backups": 10,
"pollInterval": 15
}
}
}]
}
// log4js-worker.json ####
// Will connect to master (tcp server) and send stringified log events
{
"appenders": [{
"type": "logLevelFilter",
"level": "DEBUG",
"appender": {
"type": "multiprocess",
"mode": "worker",
"loggerPort": 5001,
"loggerHost": "simonsaysdie"
}
}]
}
// ilikebeans.js ####
var cluster = require('cluster');
var immaCluster = cluster('./doyoulikebeans');
// Perform the once off configuration depending on type of cluster
if (immaCluster.isMaster) {
require('log4js').configure('log4js-master.json');
} else {
require('log4js').configure('log4js-worker.json');
}
// Standard cluster startup
immaCluster
.use(cluster.logger('run/logs'))
.use(cluster.pidfiles('run/pids'))
.listen(3000);