Commit cbd6f31b authored by astaxie's avatar astaxie

Merge pull request #1839 from JessonChan/log_rotate_fix

file rotate bug
parents 699de2ae 221306ff
...@@ -60,14 +60,11 @@ type fileLogWriter struct { ...@@ -60,14 +60,11 @@ type fileLogWriter struct {
// newFileWriter create a FileLogWriter returning as LoggerInterface. // newFileWriter create a FileLogWriter returning as LoggerInterface.
func newFileWriter() Logger { func newFileWriter() Logger {
w := &fileLogWriter{ w := &fileLogWriter{
Filename: "", Daily: true,
MaxLines: 1000000, MaxDays: 7,
MaxSize: 1 << 28, //256 MB Rotate: true,
Daily: true, Level: LevelTrace,
MaxDays: 7, Perm: 0660,
Rotate: true,
Level: LevelTrace,
Perm: 0660,
} }
return w return w
} }
...@@ -259,8 +256,8 @@ func (w *fileLogWriter) deleteOldLog() { ...@@ -259,8 +256,8 @@ func (w *fileLogWriter) deleteOldLog() {
} }
}() }()
if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*w.MaxDays) { if !info.IsDir() && info.ModTime().Add(24*time.Hour*time.Duration(w.MaxDays)).Before(time.Now()) {
if strings.HasPrefix(filepath.Base(path), w.fileNameOnly) && if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
strings.HasSuffix(filepath.Base(path), w.suffix) { strings.HasSuffix(filepath.Base(path), w.suffix) {
os.Remove(path) os.Remove(path)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment