Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MickL opened this issue Sep 11, 2017 · 4 comments
Open

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

MickL opened this issue Sep 11, 2017 · 4 comments

Comments

@MickL
Copy link

MickL commented Sep 11, 2017

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
Copy link
Owner

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
Copy link
Author

MickL commented Sep 12, 2017

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
Copy link
Owner

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
Copy link
Author

MickL commented Sep 12, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants