discord-baymax-bot/node_modules/log4js/examples/example-socket.js

46 lines
1001 B
JavaScript
Raw Permalink Normal View History

2017-03-24 04:52:08 +00:00
var log4js = require('./lib/log4js')
, cluster = require('cluster')
, numCPUs = require('os').cpus().length
, i = 0;
if (cluster.isMaster) {
log4js.configure({
appenders: [
{
type: "multiprocess",
mode: "master",
appender: {
type: "console"
}
}
]
});
console.info("Master creating %d workers", numCPUs);
for (i=0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.info("Worker %d died.", worker.pid);
});
} else {
log4js.configure({
appenders: [
{
type: "multiprocess",
mode: "worker"
}
]
});
var logger = log4js.getLogger('example-socket');
console.info("Worker %d started.", process.pid);
for (i=0; i < 1000; i++) {
logger.info("Worker %d - logging something %d", process.pid, i);
}
}