From 13dc6fb1701ad0018c702e97ed97534f47f77eb6 Mon Sep 17 00:00:00 2001 From: Nathan Schwarz Date: Mon, 22 Feb 2021 13:18:55 +0100 Subject: [PATCH] [v2.1.8]: added ability to disable worker logger --- README.md | 3 ++- package.js | 2 +- src/Cluster/ChildProcess.js | 9 ++++++++- src/logs.js | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 038cebd..921e54b 100644 --- a/README.md +++ b/README.md @@ -63,13 +63,14 @@ Both in-memory and persistent tasks are available at the same time, and can be u ## prototype - `constructor(taskMap: Object, { port: Integer, maxAvailableWorkers: Integer, refreshRate: Integer, inMemoryOnly: Boolean, messageBroker: function })` + `constructor(taskMap: Object, { port: Integer, maxAvailableWorkers: Integer, refreshRate: Integer, inMemoryOnly: Boolean, messageBroker: function, logs: String })` - `taskMap`: a map of functions associated to a `taskType` - `maxAvailableWorkers`: maximum number of child process (cores), default is set to system maximum - `port`: server port for child process servers, default set to `3008` - `refreshRate`: Worker pool refresh rate (in ms), default set to `1000` - `inMemoryOnly`: force the cluster to only pull jobs from the in-memory task queue. - `messageBroker` is optional, default set to null (see IPC section)
+ - `logs`: is one of `['all', 'error']`, default sets to `all` : if set to `'error'`, will only show the errors and warning logs. `Cluster.isMaster()`: `true` if this process is the master
diff --git a/package.js b/package.js index 9cabe26..9c8308a 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'nschwarz:cluster', - version: '2.1.7', + version: '2.1.8', summary: 'native nodejs clusterization for meteor server', git: 'https://github.com/nathanschwarz/meteor-cluster.git', documentation: 'README.md' diff --git a/src/Cluster/ChildProcess.js b/src/Cluster/ChildProcess.js index e4b4eb5..3d65f01 100644 --- a/src/Cluster/ChildProcess.js +++ b/src/Cluster/ChildProcess.js @@ -1,14 +1,21 @@ +const debug = Npm.require('debug') import StaticCluster from './StaticCluster' const process = require('process') import TaskQueue from '../TaskQueue' import ChildWorker from '../Worker/ChildWorker' class ChildProcess extends StaticCluster { - constructor(taskMap) { + constructor(taskMap, { logs = 'all' } = {}) { super() Meteor.startup(() => { TaskQueue.registerTaskMap(taskMap) }) + // enable / disable logs + if (logs === 'all') { + debug.enable('nschwarz:cluster:*') + } else { + debug.enable('nschwarz:cluster:ERROR*,nschwarz:cluster:WARNING*') + } // register listeners if this process is a worker process.on('message', ChildWorker.onMessageFromMaster) process.on('disconnect', ChildWorker.onDisconnect) diff --git a/src/logs.js b/src/logs.js index b74abea..62c799a 100644 --- a/src/logs.js +++ b/src/logs.js @@ -7,6 +7,6 @@ const errorLogger = debug('nschwarz:cluster:ERROR\t') logger.log = console.log.bind(console) warnLogger.log = console.warn.bind(console) -debug.enable('nschwarz:cluster*') +debug.enable('nschwarz:cluster:ERROR*,nschwarz:cluster:WARNING*') export { logger, warnLogger, errorLogger }