winston.transports.File ignores file creation errors
See original GitHub issueWhen adding File transport to a logger which points to a non-existing file and the directory does not have WRITE permissions, Winston does not catch ‘error’ event from the stream when it fails to create the log file. This prevents to catch the error in app code thus no one knows the file logger does not work at all because the error message from WriteStream is just stored in buffer and never gets written into the file or console.
Example code:
var logger = require('winston').Logger({
transports: [
new winston.transports.File({
filename: '/var/log/server.log',
level: 'debug'
})
],
emitErrs: true
});
logger.on('error', function (err) {
console.error('Logging error info: ', JSON.stringify(err));
});
The file creation error in WriteStream is not captured and propagated to the logger. This could be easily fixed by capturing the ‘error’ event in file.js in File.prototype._createStream.createAndFlush method by adding:
self._stream.on('error', function(err) {
self.emit('error', err);
});
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Winston not displaying error details - node.js - Stack Overflow
It is a module that I am using to log some information to a file and some to a mysql database. require('dotenv').config(); const...
Read more >winstonjs/winston - Gitter
i installed winston to use logger (for log rotation) but the logs contains ANSI ... It seems like Winston isn't logging error objects...
Read more >How to use the winston.transports.Console function in ... - Snyk
To help you get started, we've selected a few winston.transports. ... File({ filename: 'error.log', level: 'error' }), new transports.File({ filename: ...
Read more >winston - npm
It is possible to use multiple transports of the same type e.g. winston.transports.File when you construct the transport. const logger = winston ...
Read more >Node.js Logging with Winston - Reflectoring
File ({ level: "error", filename: "logs/error.log", }), new transports.Console(), ], }); module.exports = ...
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’m seeing this on
3.0.0-rc1
I’ve added the following to my bash execution script to prevent a repeat performance and provide a clue to someone examining the script as to what can go wrong.