lfshook icon indicating copy to clipboard operation
lfshook copied to clipboard

How often the files are closed?

Open soumiksamanta opened this issue 4 years ago • 2 comments

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)?

soumiksamanta avatar Dec 08 '20 19:12 soumiksamanta

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.

rifflock avatar Dec 08 '20 20:12 rifflock

Codes have performance problem. Open() Close() use too much cpus.

jinleileiking avatar Sep 07 '22 09:09 jinleileiking