I have experimented with instantiating and closing winston loggers as (half) described on https://github.com/flatiron/winston#instantiating-your-own-logger, to no avail. I run into trouble closing file transports of Winston's - walking through it's source code, I found that the proper way to close off a logger would seem to be the close
method. I expected this to take care of closing the transport file used by the logger - however that turned out to be not so.
Varying in frequency according to node.js server load, winston would still hold on to many transport files, infinitely long after the close
method had been called for them, indefinitely long after no new writes were being initiated to them. I observed that through the node.js process file descriptors table (lsof -p
). Even though close
has been called for a Winston logger, it would indefinitely keep the file descriptor of the log file "in use", i.e. the log file never gets really closed. Thus leaking file descriptors and eventually making the node.js process bump into the ulimit (-n) limit after my application has been up for long.
Should there be a specific programming pattern for draining a Winston logger such that it can be eventually closed?
Create only one logger instance and then derive children from it. In this case, winston will hold only one open file handler. Might also be better for performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With