transports.File not writing to file
See original GitHub issueI 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:
- Created 6 years ago
- Reactions:13
- Comments:18 (1 by maintainers)
Top 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 >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
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.
@mhawila nope, wrote my own logger.