From 59773dfabe3e870641df8335b1070330f38b991e Mon Sep 17 00:00:00 2001 From: Francois Date: Tue, 26 Aug 2014 06:25:59 +0200 Subject: [PATCH] Update file.go New pull request for "Panic sometimes occurs at time 00h00 on windows, then the app crashes." --- logs/file.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/logs/file.go b/logs/file.go index e80b955c..39220cc0 100644 --- a/logs/file.go +++ b/logs/file.go @@ -226,13 +226,20 @@ func (w *FileLogWriter) DoRotate() error { func (w *FileLogWriter) deleteOldLog() { dir := filepath.Dir(w.Filename) - filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + filepath.Walk(dir, func(path string, info os.FileInfo, err error) (returnErr error) { + defer func() { + if r := recover(); r != nil { + returnErr = fmt.Errorf("Unable to delete old log '%s', error: %+v", path, r) + fmt.Println(returnErr) + } + }() + if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*w.Maxdays) { if strings.HasPrefix(filepath.Base(path), filepath.Base(w.Filename)) { os.Remove(path) } } - return nil + return }) }