mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 15:00:54 +00:00
commit
fcc9d8c45f
11
logs/file.go
11
logs/file.go
@ -226,13 +226,20 @@ func (w *FileLogWriter) DoRotate() error {
|
|||||||
|
|
||||||
func (w *FileLogWriter) deleteOldLog() {
|
func (w *FileLogWriter) deleteOldLog() {
|
||||||
dir := filepath.Dir(w.Filename)
|
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 !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*w.Maxdays) {
|
||||||
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.Filename)) {
|
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.Filename)) {
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user