natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.79k stars 591 forks source link

Post rotate hook #73

Open hhh0pE opened 5 years ago

hhh0pE commented 5 years ago

Hello.

I need to run a function after logFile has been rotated. I don't see any way to do it in the code, so I implemented it myself.

There are two new callbacks: AfterCompressFunc (filepath string) BeforeDeleteFunc(filepath string) bool

First is async, second is blocking. BeforeDeleteFunc also can cancel file deleting by return FALSE, so it adds an ability to filter deleting files or do something before they will be deleted.

Both can be used to gracefully handle new log rotated, like:

lumberJackLogger.AfterCompressFunc = func(filepath string) {
        log.Println("AfterCompressFunc "+filepath)
    sendArchiveToServer(filepath)
}