question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

if the logs directory doesn't exist, it will throw ex instead of create directory

See original GitHub issue
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.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

34reactions
PierLucGagnoncommented, Apr 8, 2015

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.

18reactions
KirillGrishincommented, Nov 5, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a directory if it does not exist and then create the files ...
The Files.createDirectories() creates a new directory and parent directories that do not exist. This method does not throw an exception if the directory...
Read more >
Best Practices for exceptions - .NET - Microsoft Learn
Another way to avoid exceptions is to return null (or default) for most common error cases instead of throwing an exception.
Read more >
How to Fix the FileNotFoundException in Java.io - Rollbar
The FileNotFoundException is a checked exception in Java that occurs when an attempt to open a file denoted by a specified pathname fails....
Read more >
Copy Task - Apache Ant
If false , log a warning message, but do not stop the build, when the file to copy does not exist or one...
Read more >
Java Files - java.nio.file.Files Class - DigitalOcean
This method will not throw an exception if the directory could not be created because it already exists. FileAttribute is an optional ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found