Skip to content

Commit

Permalink
log file name bug fixed
Browse files Browse the repository at this point in the history
this bug happens when daily rotate. ex,when it is 2016-01-22 23:59:59 and need a rotate,the file name should named with 2016-01-22 but named with 2016-01-23(next day)
  • Loading branch information
JessonChan committed Jan 26, 2016
1 parent 01ccc75 commit b5a07c6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions logs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error {
if w.needRotate(len(msg), d) {
w.Lock()
if w.needRotate(len(msg), d) {
if err := w.doRotate(); err != nil {
if err := w.doRotate(when); err != nil {
fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err)
}

Expand Down Expand Up @@ -200,7 +200,7 @@ func (w *fileLogWriter) lines() (int, error) {

// DoRotate means it need to write file in new file.
// new file name like xx.2013-01-01.2.log
func (w *fileLogWriter) doRotate() error {
func (w *fileLogWriter) doRotate(logTime time.Time) error {
_, err := os.Lstat(w.Filename)
if err != nil {
return err
Expand All @@ -215,7 +215,7 @@ func (w *fileLogWriter) doRotate() error {
suffix = ".log"
}
for ; err == nil && num <= 999; num++ {
fName = filenameOnly + fmt.Sprintf(".%s.%03d%s", time.Now().Format("2006-01-02"), num, suffix)
fName = filenameOnly + fmt.Sprintf(".%s.%03d%s", logTime.Format("2006-01-02"), num, suffix)
_, err = os.Lstat(fName)
}
// return error if the last file checked still existed
Expand Down

0 comments on commit b5a07c6

Please sign in to comment.