ryankurte / winston-cluster

Winston transport for Node.js clustering
MIT License
7 stars 5 forks source link

level doesn't seem to be have a effect #7

Open MickL opened 7 years ago

MickL commented 7 years ago

I set the level to debug which works in master. But in worker it only shows error, warn and info but not debug. Colorized, timestamp, write to file etc. is working.

main.js:

const logger = require('./logger'),
winstonCluster = require('winston-cluster')

worker.js:

const logger = require('winston'),
winstonCluster = require('winston-cluster')

logger.js:

logger.remove(logger.transports.Console);

logger.add(logger.transports.Console, {
  colorize: true,
  timestamp: new Date().toLocaleTimeString(),
  level: 'debug'
});

module.exports = logger;
ryankurte commented 7 years ago

Hmm, at a guess the winston instance in the thread is pre-filtering the levels (I take it you're calling the bind methods as in the example?).

If you check out the bindTransport function here winston-cluster.js#L86 you'll notice that options is passed in to the child bind function but not used.

I have committed a branch which passes those options through, then you'll probably have to pass your log level to the winstonCluster.bindTransport(); method. Could you have a go with the branch, and if that works for you I can merge it in?

Cheers,

Ryan

MickL commented 7 years ago

Im not sure if bindTransport is what im looking for: The master-process defines all options. The childs should work by using logger = require('winston'). And they do for colorize, timestamp and levels. Only level does not work within the child processes(i see all, but debug and silly).

If i pass an option to bindTransport() i would have to require my logger.js again just to get the level and send it to the master which already has the level.

Same for (logger.js):

logger.add(logger.transports.DailyRotateFile, {
  filename: `${logDir}/.log`,
  datePattern: 'dd-MM-yyyy',
  prepend: true,
  level: 'silly',
  flags: 'a'
});

Working fine, except for level (only shows up to level info for child processes, not debug or silly)

ryankurte commented 7 years ago

Tested it out and that was it. Have updated the library to fix the problem (with a slight change to the API to take winston instances where useful) and the updated example in the readme as to how to use it.

You do need to bind the winston.transport.Cluster transport to the winston instance in the client thread, that's not done for you at this stage.

Let me know if that solves your problem?

MickL commented 7 years ago

Doesn't this make it more circular? Before, within child process, we just had to do:

const logger = require('winston');
const winstonCluster = require('winston-cluster');
winstonCluster.bindTransport();

And everything was working fine as logger options were defined in the master. Only level was not adopted by child processes.