winston.transports.File fails to log when filename option is in home directory
See original GitHub issueWhen the filename for a File transport is in the home directory, and the path starts with a tilde, no log file is created anywhere and no error is thrown.
// winston.version === '2.2.0'
var logger = new winston.Logger()
logger.add(winston.transports.File, { filename: '~/.my.log', level : 'verbose' })
logger.verbose('I\'m not logging')
Just as the fs module throws when the tilde is used in paths I would expect winston to throw as well. I can’t find any way to catch the error using handleExceptions
but I’m new to using winston.
The File transport’s stream emits a ENOENT error because the dirname “~” doesn’t exist but I prefer to do,
if(this.dirname === '~')
this.dirname = process.env.HOME
I would just expect something thrown or some magic to make it work since this can be dealt with in the File transport constructor.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
Logging to file with winston fails when in other module
logger.js var winston = require('winston'); var logger = new (winston.Logger)({ transports: [ new(winston.transports.File)({ filename:'PATH_TO_LOG_FILE' ...
Read more >How To Use Winston to Log Node.js Applications on Ubuntu ...
Next, instantiate a new winston logger with file and console transports using the properties defined in the options variable:.
Read more >Complete Winston Logger Guide With Hands-on Examples
There are over 30 transports options, which include logging out into a single file, the console, or to 3rd party systems, such as...
Read more >How to use the winston.createLogger function in winston - Snyk
transports.File({ filename: 'logs/error.log', level: 'error' }), new ...
Read more >Learn winstonjs - Master Logging in Node.js
format: winston.format.json(), defaultMeta: { service: 'user-service' }, transports: [ new winston.transports.File({ filename: 'error.log', ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Right but it fails silently. I’m saying it should throw or there should be a configuration to make it work; throwing would probably be better than nothing.
@totopsy yes its an installed application in windows, so instead of writing the log in a subfolder of Program Files the log is written to AppData… I found a solution now though, sorry for the hijack 😃