Skip to content

Commit

Permalink
refactor: make rotate private
Browse files Browse the repository at this point in the history
  • Loading branch information
qazwsxedckll committed Mar 5, 2024
1 parent c51d124 commit ce19768
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rotate_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewRotateFile(directory string, basename string, rotateSize int, opts ...Op
opt(rf)
}

rf.Rotate()
rf.rotate()

return rf, nil
}
Expand All @@ -46,13 +46,13 @@ func (r *RotateFile) Write(p []byte) (int, error) {
r.written += n

if r.written > r.rotateSize {
r.Rotate()
r.rotate()
} else {
r.count++
if r.count >= r.checkEveryN {
r.count = 0
if time.Now().After(r.lastRotate.Add(r.rotateInterval)) {
r.Rotate()
r.rotate()
}
}
}
Expand All @@ -69,7 +69,7 @@ func (r *RotateFile) logFileName() (string, time.Time) {
return r.filepath + "." + now.Format("20060102-150405.000000000") + "." + hostname + "." + fmt.Sprint(os.Getpid()) + ".log", now
}

func (r *RotateFile) Rotate() {
func (r *RotateFile) rotate() {
filename, now := r.logFileName()

if now.After(r.lastRotate) {
Expand Down

0 comments on commit ce19768

Please sign in to comment.