From 31c746d9d758bec24c7559ea58541982a8aa4106 Mon Sep 17 00:00:00 2001 From: two Date: Thu, 26 Jul 2018 14:34:25 +0800 Subject: [PATCH] fix all confict --- logs/file.go | 36 ++++++------------------------------ logs/logger_test.go | 10 ---------- 2 files changed, 6 insertions(+), 40 deletions(-) diff --git a/logs/file.go b/logs/file.go index 21c4438e..588f7860 100644 --- a/logs/file.go +++ b/logs/file.go @@ -306,7 +306,6 @@ func (w *fileLogWriter) doRotate(logTime time.Time) error { goto RESTART_LOGGER } -<<<<<<< HEAD if w.Hourly { format = "2006010215" openTime = w.hourlyOpenTime @@ -315,31 +314,18 @@ func (w *fileLogWriter) doRotate(logTime time.Time) error { openTime = w.dailyOpenTime } + // only when one of them be setted, then the file would be splited if w.MaxLines > 0 || w.MaxSize > 0 { - for ; err == nil && num <= 999; num++ { + for ; err == nil && num <= w.MaxFiles; num++ { fName = w.fileNameOnly + fmt.Sprintf(".%s.%03d%s", logTime.Format(format), num, w.suffix) _, err = os.Lstat(fName) } } else { - fName = fmt.Sprintf("%s.%s%s", w.fileNameOnly, openTime.Format(format), w.suffix) - _, err = os.Lstat(fName) - for ; err == nil && num <= 999; num++ { - fName = w.fileNameOnly + fmt.Sprintf(".%s.%03d%s", openTime.Format(format), num, w.suffix) - _, err = os.Lstat(fName) - } -======= - // only when one of them be setted, then the file would be splited - if w.MaxLines > 0 || w.MaxSize > 0 { - for ; err == nil && num <= w.MaxFiles; num++ { - fName = w.fileNameOnly + fmt.Sprintf(".%s.%03d%s", logTime.Format("2006-01-02"), num, w.suffix) - _, err = os.Lstat(fName) - } - } else { - fName = w.fileNameOnly + fmt.Sprintf(".%s.%03d%s", w.dailyOpenTime.Format("2006-01-02"), num, w.suffix) + fName = w.fileNameOnly + fmt.Sprintf(".%s.%03d%s", openTime.Format(format), num, w.suffix) _, err = os.Lstat(fName) w.MaxFilesCurFiles = num ->>>>>>> old/develop } + // return error if the last file checked still existed if err == nil { return fmt.Errorf("Rotate: Cannot find free log number to rename %s", w.Filename) @@ -383,31 +369,21 @@ func (w *fileLogWriter) deleteOldLog() { if info == nil { return } -<<<<<<< HEAD if w.Hourly { - if !info.IsDir() && info.ModTime().Add(1*time.Hour*time.Duration(w.MaxHours)).Before(time.Now()) { + if !info.IsDir() && info.ModTime().Add(1 * time.Hour * time.Duration(w.MaxHours)).Before(time.Now()) { if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) && strings.HasSuffix(filepath.Base(path), w.suffix) { os.Remove(path) } } } else if w.Daily { - if !info.IsDir() && info.ModTime().Add(24*time.Hour*time.Duration(w.MaxDays)).Before(time.Now()) { + if !info.IsDir() && info.ModTime().Add(24 * time.Hour * time.Duration(w.MaxDays)).Before(time.Now()) { if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) && strings.HasSuffix(filepath.Base(path), w.suffix) { os.Remove(path) } } } -======= - - if !info.IsDir() && info.ModTime().Add(24 * time.Hour * time.Duration(w.MaxDays)).Before(time.Now()) { - if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) && - strings.HasSuffix(filepath.Base(path), w.suffix) { - os.Remove(path) - } - } ->>>>>>> old/develop return }) } diff --git a/logs/logger_test.go b/logs/logger_test.go index 870b0d81..78c67737 100644 --- a/logs/logger_test.go +++ b/logs/logger_test.go @@ -30,13 +30,8 @@ func TestFormatHeader_0(t *testing.T) { if tm.Year() >= 2100 { break } -<<<<<<< HEAD h, _, _ := formatTimeHeader(tm) - if tm.Format("2006/01/02 15:04:05.999 ") != string(h) { -======= - h, _ := formatTimeHeader(tm) if tm.Format("2006/01/02 15:04:05.000 ") != string(h) { ->>>>>>> old/develop t.Log(tm) t.FailNow() } @@ -53,13 +48,8 @@ func TestFormatHeader_1(t *testing.T) { if tm.Year() >= year+1 { break } -<<<<<<< HEAD h, _, _ := formatTimeHeader(tm) - if tm.Format("2006/01/02 15:04:05.999 ") != string(h) { -======= - h, _ := formatTimeHeader(tm) if tm.Format("2006/01/02 15:04:05.000 ") != string(h) { ->>>>>>> old/develop t.Log(tm) t.FailNow() }