Skip to content

Commit

Permalink
filerotate: don't add .txt to file names
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Jun 14, 2024
1 parent 51cde15 commit 40e0c12
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions filerotate/filerotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,32 @@ func New(config *Config) (*File, error) {
return file, nil
}

func MakeDailyRotateInDir(dir string, fileUniqueName string) func(time.Time, time.Time) string {
func MakeDailyRotateInDir(dir string, fileNameSuffix string) func(time.Time, time.Time) string {
return func(creationTime time.Time, now time.Time) string {
if IsSameDay(creationTime, now) {
return ""
}
name := now.Format("2006-01-02")
if fileUniqueName != "" {
name = name + "-" + fileUniqueName
if fileNameSuffix != "" {
name = name + "-" + fileNameSuffix
} else {
name += ".txt"
}
name += ".txt"
return filepath.Join(dir, name)
}
}

func MakeHourlyRotateInDir(dir string, fileUniqueName string) func(time.Time, time.Time) string {
func MakeHourlyRotateInDir(dir string, fileNameSuffix string) func(time.Time, time.Time) string {
return func(creationTime time.Time, now time.Time) string {
if IsSameHour(creationTime, now) {
return ""
}
name := now.Format("2006-01-02_15")
if fileUniqueName != "" {
name = name + "-" + fileUniqueName
if fileNameSuffix != "" {
name = name + "-" + fileNameSuffix
} else {
name += ".txt"
}
name += ".txt"
return filepath.Join(dir, name)
}
}
Expand Down

0 comments on commit 40e0c12

Please sign in to comment.