easyloggingpp icon indicating copy to clipboard operation
easyloggingpp copied to clipboard

Enable reopening log files

Open bhjortsberg opened this issue 6 years ago • 3 comments

Once a Logger is configured the application keeps the file open. This is due to that LogStreamReferenceMap is keeping a reference to the FileStream object and unregistering the Logger will never close the file.

Switching to weak_ptr in LogStreamReferenceMap i.e. not holding a reference makes unregistering logger close the file if no other reference to FileStream object exist.

The use case is for logrotation where logrotation removes the logfile and sends a SIGHUP to the application. This fix makes it possible to reconfigure the logger to reopen the log file. I added a sample to illustrate the use case.

This is a

  • [ ] Breaking change
  • [ ] New feature
  • [x] Bugfix

I have

  • [x] Merged in the latest upstream changes
  • [ ] Updated CHANGELOG.md
  • [ ] Updated README.md
  • [x] Run the tests

bhjortsberg avatar Dec 08 '17 10:12 bhjortsberg

Apparently unit test fails, I haven't looked at them yet. Any comment on this change, does it break the architecture? Or is it just the tests that need to be updated?

bhjortsberg avatar Dec 08 '17 10:12 bhjortsberg

Tests passes when I run them locally with my latest update.

Travis CI build seem to have some problem with cmake when building googletest.

bhjortsberg avatar Dec 19 '17 08:12 bhjortsberg

I would love to see this added, as without using the linux logrotate utility is impossible, as that relies on the program being able to close and reopen the log file.

BrainStone avatar Dec 11 '19 10:12 BrainStone