natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.81k stars 593 forks source link

Implement BeforeDeleteFunc #199

Open kaiiorg opened 10 months ago

kaiiorg commented 10 months ago

Looking to use lumberjack for a personal project and the feature request in #195 would be a nice-to-have, so I implemented it myself.

I did this by adding a function pointer to the Logger struct and calling it just before deleting the file (after checking if it is nil, of course). I copy/pasted the TestCleanupExistingBackups test to TestCleanupExistingBackups_CallsCallback (so I know we're testing it with a known good test) and just increment a counter and validate that counter is the number we expect.