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.

winston.transports.File fails to log when filename option is in home directory

See original GitHub issue

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

More in Gist

// 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:open
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
matuttercommented, Nov 4, 2016

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.

0reactions
HugoJLFerreiracommented, Jun 7, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

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