lfshook
lfshook copied to clipboard
How often the files are closed?
Does the fd close at the time of logrus.Exit()?
I see there is a defer fd.close()
in fileWrite()
which is called by the Fire()
Does it mean that for every entry passed, the file is opened and then closed?
Wouldn't it be better if the close of the files be done during logrus.Exit(0)?
That's a good question. The idea here is that it will open and close on every fire to avoid holding on to a file descriptor and potentially blocking access to that file or leaking file descriptors. Maybe I was being overly cautious by designing it this way, but it seemed prudent to only maintain the file descriptor while using the file. Just looking at the Go documentation it seems like closing at the end of the call is the best practice (though there is discussion around whether to use defer or not due to the possibility of losing error messages).
Is there any benchmarking you've seen that shows that frequent opens and closes causes a performance hit? I've seen some posts saying that not closing can lead to resource leak, but I'm happy to read an alternative opinion.
Codes have performance problem. Open() Close() use too much cpus.