-
Notifications
You must be signed in to change notification settings - Fork 5
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
Does winston-cluster support winston.containers? #4
Comments
Hey @johnmcilwain, With respect to your email, and issue #1, if winston works clustered now you may not need this. At the time that I wrote it, it didn't, and I needed to make sure logging would be handled by only one process (particularly for file writing), which it has been doing in production for a year or so now. As it stands, it only overwrites the transports for the default handler, so does not currently support containers / instances. You can see on line 70 how the master passes log events to the default winston instance, and on line 84 how the child transport is overwritten to use the cluster IPC. If you need containers / instances you could probably alter the bindTransport function to take an optional winston instance to overwrite the underlying transport for a provided instance instead of the default instance, though I don't know what other magic occurs under the hood of winston. Something like: var bindTransport = exports.bindTransport = function(instance) {
if(typeof instance !== 'undefined') {
instance.remove(winston.transports.Console);
instance.add(winston.transports.Cluster, {});
} else {
winston.remove(winston.transports.Console);
winston.add(winston.transports.Cluster, {});
}
} Then in the child process: var lw = winston.loggers.get('logwinston');
winstonCluster.bindTransport(lw); Might work, though would route all messages to the default handler in the parent. If you want these to pass back to separate instances in the parent, an additional field (instance, ie. 'logwinston') may need to be passed through the IPC and used to select which instance to write back to. As an aside from that, I believe you will need to instantiate the loggers in both the parent and child processes ( If you decide to implement any of this, I would welcome a pull request! Good luck, Ryan |
Thanks Ryan, I appreciate the feedback!
I'll give it a shot and if I get it working, I'll do a pull request.
…-john
________________________________
From: Ryan <notifications@github.com>
Sent: Tuesday, November 29, 2016 1:12:55 AM
To: ryankurte/winston-cluster
Cc: johnnymac949; Mention
Subject: Re: [ryankurte/winston-cluster] Does winston-cluster support winston.containers? (#4)
Hey @johnmcilwain<https://github.com/johnmcilwain>,
With respect to your email, and issue #1<#1>, if winston works clustered now you may not need this. At the time that I wrote it, it didn't, and I needed to make sure logging would be handled by only one process (particularly for file writing), which it has been doing in production for a year or so now.
As it stands, it only overwrites the transports for the default handler, so does not currently support containers / instances.
You can see on line 70<https://github.com/ryankurte/winston-cluster/blob/master/lib/winston-cluster.js#L70> how the master passes log events to the default winston instance, and on line 84<https://github.com/ryankurte/winston-cluster/blob/master/lib/winston-cluster.js#L84> how the child transport is overwritten to use the cluster IPC.
If you need containers / instances you could probably alter the bindTransport function to take an optional winston instance to overwrite the underlying transport for a provided instance instead of the default instance, though I don't know what other magic occurs under the hood of winston.
Something like:
var bindTransport = exports.bindTransport = function(instance) {
if(typeof instance !== 'undefined') {
instance.remove(winston.transports.Console);
instance.add(winston.transports.Cluster, {});
} else {
winston.remove(winston.transports.Console);
winston.add(winston.transports.Cluster, {});
}
}
Then in the child process:
var lw = winston.loggers.get('logwinston');
winstonCluster.bindTransport(lw);
Might work, though would route all messages to the default handler in the parent.
If you want these to pass back to separate instances in the parent, an additional field (instance, ie. 'logwinston') may need to be passed through the IPC and used to select which instance to write back to.
As an aside from that, I believe you will need to instantiate the loggers in both the parent and child processes (var category1 = winston.loggers.get('logwinston');).
If you decide to implement any of this, I would welcome a pull request!
Good luck,
Ryan
-
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#4 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AHX4e1FIhp168Mf7eY38XpVrz4QMGN8kks5rC3wXgaJpZM4K8F7Q>.
|
I am probably doing something dumb, but I can't get it to work. My sample code:
The text was updated successfully, but these errors were encountered: