var transports = [];
transports.push(new winston.transports.DailyRotateFile({
name: 'file',
datePattern: '.yyyy-MM-ddTHH',
filename: path.join(__dirname, "logs", "log_file.log")
}));
var logger = new winston.Logger({transports: transports});
logger.info("current scheduled_mt_task count");
If the subdirectory /logs doesn't exist, it will throw exception like can't open file logs/log_file.log20150213XXX ,
I think winston should automatic create the sub directory instead of asking users to manually create it.
I think it should be up to the dev to make sure that their environment is properly provisioned.
also, related to pr #581 and issue #511
I vote for an option for this. By default the log directory shouldn't be created, but with an option like createDirectory set to true, it would be really convenient if Winston created said directory.
+1
Agree with @ambbell here. It is up to the consumer of winston to ensure that their logs directory exists.
+1
Other logging tools such as NLog for .NET and SLF4J for Java are able to create the folder on the fly. Also, why does Winston fails if it cannot write the log? Why an entire application should fail just because it is not able to log?
@indexzero Will you guys accept a PR for @PierLucGagnon's suggestion? About createDirectory option? I find current behavior very inconvenient and (as mentioned by @guillegr123) inconsistent with how other logging frameworks work, so it contradicts with user expectations.
I mean, why don't you take a step further and say that its devs responsibility to make sure a logging FILE is created beforehand?
Since folders called /logs will be ignored if you use one of the common gitignores the missing folder exception is a common problem when I deploy my apps to new environments. I hope the pull request will be accepted
@indexzero But why? When you say something like "I think", you need to provide reasoning for this, no? My reason to have this option is because usually logs directory is not under version control, and will not be created when cloning a repo - boom you have an error when trying to run it. I am not even talking about automatically deployed environments.
Workaround: add this instruction prior to transports declaration:
fs.mkdir('./logs', (err) => { /* no-op */ })
Most helpful comment
I vote for an option for this. By default the log directory shouldn't be created, but with an option like
createDirectoryset to true, it would be really convenient if Winston created said directory.