Update file.go
New pull request for "Panic sometimes occurs at time 00h00 on windows, then the app crashes."
Showing
1 changed file
with
9 additions
and
2 deletions
| ... | @@ -226,13 +226,20 @@ func (w *FileLogWriter) DoRotate() error { | ... | @@ -226,13 +226,20 @@ func (w *FileLogWriter) DoRotate() error { |
| 226 | 226 | ||
| 227 | func (w *FileLogWriter) deleteOldLog() { | 227 | func (w *FileLogWriter) deleteOldLog() { |
| 228 | dir := filepath.Dir(w.Filename) | 228 | dir := filepath.Dir(w.Filename) |
| 229 | filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { | 229 | filepath.Walk(dir, func(path string, info os.FileInfo, err error) (returnErr error) { |
| 230 | defer func() { | ||
| 231 | if r := recover(); r != nil { | ||
| 232 | returnErr = fmt.Errorf("Unable to delete old log '%s', error: %+v", path, r) | ||
| 233 | fmt.Println(returnErr) | ||
| 234 | } | ||
| 235 | }() | ||
| 236 | |||
| 230 | if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*w.Maxdays) { | 237 | if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*w.Maxdays) { |
| 231 | if strings.HasPrefix(filepath.Base(path), filepath.Base(w.Filename)) { | 238 | if strings.HasPrefix(filepath.Base(path), filepath.Base(w.Filename)) { |
| 232 | os.Remove(path) | 239 | os.Remove(path) |
| 233 | } | 240 | } |
| 234 | } | 241 | } |
| 235 | return nil | 242 | return |
| 236 | }) | 243 | }) |
| 237 | } | 244 | } |
| 238 | 245 | ... | ... |
-
Please register or sign in to post a comment