-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Shared Transports #101
Comments
@bluepines Why do you need two file transports? This is currently not supported. |
I'd also like this, my use case is:
The different files get different logrotate, persistence, etc. treatment. I can also see use cases more generally for multiple transports of the same type with different configurations. |
@ryan-roemer That is already possible through configurable log levels. |
@indexzero Thanks for the response. Could you post a quick example? I don't see how to do this from the readme. Ideally, I want info-everything higher in one log, and duplicate of the errors only in another. I was trying to do this:
And, apologies for clogging this issue! |
I too am stumped by how to do this. @ryan-roemer did you figure it out in the end? |
@domenic Nope -- my use case morphed into using two different transports, thus avoiding the issue. I am interested in finding out a good example of how to do this with the same transport though! |
Couldn't you use 2 different loggers instead? I needed one for request logging and the other for debug/std out logging, so I just created 2 instances.
|
@rickcrawford Thanks for offering some suggestions. Unfortunately, my ideal use case would be to make this a matter of pure configuration -- (1) I log at a different levels using one logger, and (2) I have different log outputs at different levels (and some multiply overlapping). Having |
@ryan-roemer I agree it should be similar to log4j's approach of having multiple loggers assigned to 1 root logger. |
+1 for this. My example use case: var logger = new (winston.Logger)({
exitOnError: false, //don't crash on exception
transports: [
new (winston.transports.Console)(), //always use the console
new (winston.transports.File)({ filename: 'logs/server.log' }), //log everything to the server.log
new (winston.transports.File)({ level: 'error', filename: 'logs/error.log', handleExceptions: true }), //log errors and exceptions to the error.log
new (winston.transports.File)({ level: 'warn', filename:'logs/warn.log' }), //log warn to the warn.log
new (winston.transports.File)({ level: 'info', filename:'logs/info.log' }) //log info to the info.log
]
}); |
Yeah again +1 for this. @darcy 's use case makes sense to me. Or something like this var winston = require('winston');
winston.add(winston.transports.File, { filename: '/path/to/logfile.log', json: false, maxsize: 10485760, level: 'info' });
winston.add(winston.transports.File, { filename: '/path/to/errorfile.log', json: false, maxsize: 10485760, level: 'error' }); Seems weird you can specify the levels with the transport but then can't add a different one for different levels. |
@k0nG Looks like a one line change? Pull-request? |
Fixed ^^ |
Awesome, thanks! |
I'm still getting this error in 0.7.2 and @stephenbeeson was asking 2mo ago at #149 Are you sure it's working? |
That test still fails for me, I don't think the other commit fixed it. I'd reopen this issue if I could |
@ALL, am I right that winston still has not support multiple File transports in one logger? In my testing, the error mesg sometimes go to warn.log file.
|
@ash211 @gdbtek or anyone who see this thread, new winston.transports.File({ filename: './logs/error.log', name: 'file.error', level: 'error' }),
new winston.transports.File({ filename: './logs/info.log', name: 'file.info', level: 'info' }),
new winston.transports.File({ filename: './logs/debug.log', name: 'file.debug', level: 'debug' }) |
@yhpark and @ash211 , I actually set name and filename fields but it still does not work as expected. If anyone see what I'm missing, please let me know. Thanks.
|
How can a given transport once it logged a message to keep it only for itself and not pass it along to other transports? I want to prevent copying the same log message into multiple transports, if at least one handled it. |
Thanks for this everyone. Works great! |
I bumped up against this issue within 5 minutes of trying to use winston in my project, and had to hunt for a solution here. The fact that winston doesn't like multiple transports of the same type isn't mentioned in the documentation, and neither is the Wanting to log different error levels to different files can't possibly be an obscure use case, and the transport docs suggest the transports are composable when in fact they rely on the transport having a unique name (which I assume defaults to the transport type's name). The docs could be much clearer on this point. |
Fixed in |
Hi, I have followed along with the docs and these past issues. I no longer receive the original issues but I am only getting output to one file :
|
I am having trouble setting up shared transports.
I am using this method to add the shared transports:
Basically, I have two types of loggers one "debugLogger", and then a large number of "specificDebugLoggers". I want the specific debug loggers to each get their own file, but I also want them to log output to the main debug file.
However, when I try and share the transports, I get this error:
Here is what I am doing:
The text was updated successfully, but these errors were encountered: