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.

transports.File not writing to file

See original GitHub issue

I know this was already asked, several times, but either there was no fix, or it just got closed.

$ npm -v 4.4.4

winston: 2.3.1

My logger:

const winston = require('winston');

var logger = new (winston.Logger)({
  /*level: 'error',*/                    // doesn't make a difference
  exitOnError: true,
  transports: [
    new (winston.transports.File)({
      filename: __dirname + '/error.log',
      level: 'error',
      handleExceptions: true,
      humanReadableUnhandledException: true,
      json: true
    }),
    new (winston.transports.Console)()
  ]
});

The console transport works fine when calling e.g.

logger.log('error', 'some message', trace);

But the file transport refuses to work. It doesn’t matter if the file exists or not. It worked fine when I used the default logger winston.log('error', 'bla', someThing);. I also invoke the onLogging event:

logger.on('logging', (transport, level, msg, meta) => {
  if(level === 'error' || level === 'warn'){
    // tell the user that something went wrong.
  }
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
mhugginscommented, Aug 21, 2017

I don’t recall, but I remember running into an issue where the file and/or directory didn’t exist already. Winston won’t create the directory for you, it needs to already exist.

5reactions
snwflakecommented, Oct 21, 2017

@mhawila nope, wrote my own logger.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Winston is not writing logs to files - node.js - Stack Overflow
The existing transport for console logging works fine, and I did check pm2 logs and saw the logs, but the transports for files...
Read more >
Winston does not write file - Glitch Help
I have a problem - not writing to the file. The recording is done by winston. I test it on the server of...
Read more >
Node.js Logging with Winston - Reflectoring
In the transport section let's replace the new transports.Console() in our logger.js to new transports.File() : const { createLogger, ...
Read more >
winston - npm
A multi-transport async logging library for Node.js. ... transports.file ] }); logger.info('Will not be logged in either transport!') ...
Read more >
logging in JavaScript with Winston.js - ZetCode
Logging is not limited to identifying errors in software development. ... Winston comes with three core transports: console, file, and HTTP.
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