robtweed / ewd-qoper8

Node.js Message Queue and Multi-Process Manager
24 stars 5 forks source link

Better logging #5

Closed killmenot closed 7 years ago

killmenot commented 7 years ago

Hi @robtweed

During working with ewd-qoper8 I found that in some places in the code we have logging statements like:

// case-1
if (this.log) console.log('more items found on queue - processing again');

and

// case-2
console.log('No worker processes are running');
console.log('Master process will now shut down');

I'd like to propose you to update logging by using the debug module for cases like case-1

// ewd-qoper8.js
var debug = require('debug')('ewd-qoper8:master')

var qoper8 = function() {
  ...
  this.debug = debug;
  ...
}

// any-file-where-log-is-used.js
this.debug('more items found on queue - processing again');

We can define logging with passing DEBUG env variable. Quick examples:

DEBUG=ewd-qoper8:* node test1.js
DEBUG=ewd-qoper8:master node test2.js

Pros:

Cons:

robtweed commented 7 years ago

This would probably be the way to do it if I was re-writing ewd-qoper8 from scratch. A lot of modules that use it (eg QEWD.js) expect the logging in ewd-qoper8 to work the way it currently does (using console.log), so the impact of what you suggest would be potentially very far-reaching. I'm therefore not sure it's a good idea.