diff --git a/flog.go b/flog.go index b986f97..123368c 100644 --- a/flog.go +++ b/flog.go @@ -13,12 +13,20 @@ import ( // Generate generates the logs with given options func Generate(option *Option) error { - splitCount := 1 - created := time.Now() + var ( + splitCount = 1 + created = time.Now() + + interval time.Duration + delay time.Duration + ) - delay := time.Duration(0) if option.Delay > 0 { - delay = time.Duration(option.Delay*float64(time.Second/time.Millisecond)) * time.Millisecond + interval = time.Duration(option.Delay * float64(time.Second)) + delay = interval + } + if option.Sleep > 0 { + interval = time.Duration(option.Sleep * float64(time.Second)) } logFileName := option.Output @@ -29,21 +37,17 @@ func Generate(option *Option) error { if option.Forever { for { - if delay > 0 { - time.Sleep(delay) - } + time.Sleep(delay) log := NewLog(option.Format, created) writer.Write([]byte(log + "\n")) - created = created.Add(time.Duration(option.Sleep*float64(time.Second/time.Millisecond)) * time.Millisecond) + created = created.Add(interval) } } if option.Bytes == 0 { // Generates the logs until the certain number of lines is reached for line := 0; line < option.Number; line++ { - if delay > 0 { - time.Sleep(delay) - } + time.Sleep(delay) log := NewLog(option.Format, created) writer.Write([]byte(log + "\n")) @@ -56,15 +60,13 @@ func Generate(option *Option) error { splitCount++ } - created = created.Add(time.Duration(option.Sleep*float64(time.Second/time.Millisecond)) * time.Millisecond) + created = created.Add(interval) } } else { // Generates the logs until the certain size in bytes is reached bytes := 0 for bytes < option.Bytes { - if delay > 0 { - time.Sleep(delay) - } + time.Sleep(delay) log := NewLog(option.Format, created) writer.Write([]byte(log + "\n")) @@ -78,7 +80,7 @@ func Generate(option *Option) error { splitCount++ } - created = created.Add(time.Duration(option.Sleep*float64(time.Second/time.Millisecond)) * time.Millisecond) + created = created.Add(interval) } } diff --git a/option.go b/option.go index 43dd5dc..2f453d1 100644 --- a/option.go +++ b/option.go @@ -22,7 +22,7 @@ Options: -n, --number integer number of lines to generate. -b, --bytes integer size of logs to generate (in bytes). "bytes" will be ignored when "number" is set. - -s, --sleep numeric creation time interval for each log (in seconds). It does not actually sleep. + -s, --sleep numeric fix creation time interval for each log (in seconds). It does not actually sleep. -d, --delay numeric delay log generation speed (in seconds). -p, --split-by integer set the maximum number of lines or maximum size in bytes of a log file. with "number" option, the logs will be split whenever the maximum number of lines is reached.