Skip to content

Commit

Permalink
check to distinguish between current log file and rotated log files
Browse files Browse the repository at this point in the history
  • Loading branch information
zakk616 authored Aug 22, 2024
1 parent e6e5153 commit c66470f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,13 @@ func (l *fileLogger) logPurge(fname string) {
if entry.IsDir() || entry.Name() == lBase || !strings.HasPrefix(entry.Name(), baseWithoutExt+".") {
continue
}
if stamp, found := strings.CutPrefix(entry.Name(), fmt.Sprintf("%s.", baseWithoutExt)); found {
_, err := time.Parse("2006:01:02:15:04:05.999999999", strings.Replace(stamp, ".", ":", 5))
if err == nil {
backups = append(backups, entry.Name())
if strings.HasSuffix(entry.Name(), ".log") {
if stamp, found := strings.CutPrefix(entry.Name(), fmt.Sprintf("%s.", baseWithoutExt)); found {
stamp = strings.TrimSuffix(stamp, ".log")
_, err := time.Parse("2006:01:02:15:04:05.999999999", strings.Replace(stamp, ".", ":", 5))
if err == nil {
backups = append(backups, entry.Name())
}
}
}
}
Expand Down

0 comments on commit c66470f

Please sign in to comment.