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.
}
});
I'm having the same problem.
I have the same issue and I have to say I have encountered a number of questions asking the same thing. Some from 2 years back!! Looks like winston is not going to fix this one!
@mhuggins and @snwflake did you guys find a solution to this?
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.
having same issue. any news on this?
@mhawila nope, wrote my own logger.
I'm encountering the same issue.
winston.exceptions.handle(
new winston.transportsConsole(),
new winston.transports.File({ filename: 'logs/test.log' })
);
throw new Error('Exception Handler');
At first this log to both console and file, but the next hour it doesn't write to file, but still log to console.
Any Idea?
Set
exitOnError: false;
Resolve my problem, I think because winston exit with no status code.
I had encountered with same issue and looks like winston failed to handle relative path. For an example, winston failed to create file when i use logs/errors.log but its started working fine when i set complete path like ${__dirname}/logs/error.log.
Hope it will help!
whats wrong with this repo, i don't want use it any more~!
I think it has something to do with the path you set for filename .
If the filename just like /a/b/error.log , the directory b corresponding to the path /a/b must exist before the error.log file can be generated.
So , u just need to make sure that the directory where error.log is located exists.
Otherwise , use winston-daily-rotate-file module , it will auto generated directory .
duplicate #875
duplicate to #1465
I'm not sure what's specifically causing it, but what caused this for me was I was running a synchronous script that has heavy synchronous read and writes, which also encountered file system errors:
"EISDIR: illegal operation on a directory, read"
When the error was there (the script carried on for a little while afterword), the script exited too fast for the logs to be flushed and the files were never written. Without the error, even though it was the exact same script, the logs are created.
Here are some documented ways to get around this: https://github.com/winstonjs/winston/blob/master/UPGRADE-3.0.md#winstonlogger
Most helpful comment
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.