Please keep in mind that this issue tracker should be used for reporting bugs or proposing improvements to the Redis server.

Generally, questions about using Redis should be directed to the community:

It is also possible that your question was already asked here, so please do a quick issues search before submitting. Lastly, if your question is about one of Redis' clients, you may to contact your client's developers for help.

Why is redis log file opened/closed every time a log is recorded?

https://github.com/redis/redis/blob/123cc1a1bca41233e711fd9b6a54d6901e72c6ce/src/server.c#L1557-L1600 That said, please feel free to replace all this with your question :)

Comment From: yoav-steinberg

I'd assume it's to keep the log consistent. There are some scenarios to consider: * If Redis crashes, it'll be good to make sure the file was closed. * If there's a power or OS failure we can't even rely on the OS to close the file for us. * In case we're using logrotate or other similar log maintenance apps that need to rename/delete the file.

Comment From: andyxning

Item 3 sounds a reasonable clue for me. Others will always be problematic when the circumstances are encountered.

Yours Sincerely, Andy Xie

yoav-steinberg @.***> 于2021年10月7日周四 下午11:10写道:

I'd assume it's to keep the log consistent. There are some scenarios to consider:

  • If Redis crashes, it'll be good to make sure the file was closed.
  • If there's a power or OS failure we can't even rely on the OS to close the file for us.
  • In case we're using logrotate or other similar log maintenance apps that need to rename/delete the file.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/redis/redis/issues/9609#issuecomment-937886538, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASLC2CETCLPYN2EPHHJGILUFWZ45ANCNFSM5FN75ICQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Comment From: madolson

Redis also generally doesn't write to the log very often, so spending the effort to make it consistent makes the code more straightforward.

Comment From: yossigo

A disadvantage of re-opening the file every time is the inability to log an error about running out of file descriptors (which we normally shouldn't).