Skip to content

Commit

Permalink
fix unique name for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Mar 30, 2024
1 parent 4d18325 commit b50a481
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions filerotate/filerotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,37 @@ func New(config *Config) (*File, error) {
return file, nil
}

func MakeDailyRotateInDir(dir string, prefix string) func(time.Time, time.Time) string {
func MakeDailyRotateInDir(dir string, fileUniqueName 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 prefix != "" {
name = "-" + prefix + "-" + name
if fileUniqueName != "" {
name = name + "-" + fileUniqueName
}
name += ".txt"
return filepath.Join(dir, name)
}
}

func MakeHourlyRotateInDir(dir string, logUniqueName string) func(time.Time, time.Time) string {
func MakeHourlyRotateInDir(dir string, fileUniqueName 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 logUniqueName != "" {
name = "-" + logUniqueName + "-" + name
if fileUniqueName != "" {
name = name + "-" + fileUniqueName
}
name += ".txt"
return filepath.Join(dir, name)
}
}

// NewDaily creates a new file, rotating daily in a given directory
func NewDaily(dir string, logUniqueName string, didClose func(path string, didRotate bool)) (*File, error) {
daily := MakeDailyRotateInDir(dir, logUniqueName)
func NewDaily(dir string, fileUniqueName string, didClose func(path string, didRotate bool)) (*File, error) {
daily := MakeDailyRotateInDir(dir, fileUniqueName)
config := Config{
DidClose: didClose,
PathIfShouldRotate: daily,
Expand Down

0 comments on commit b50a481

Please sign in to comment.