in cmd/log-generator/log-generator.go [57:89]
func writeLog(logEntry string, instanceId int) {
curFilePath := path.Join(*outPutPath, fmt.Sprintf("%s%d.log", *filePrefix, instanceId))
fmt.Printf("Creating file %s\n", curFilePath)
os.MkdirAll(*outPutPath, 0755)
f, _ := os.Create(curFilePath)
fileSize := 0
// add jitter here to ensure multiple stream will not write at same time.
r := time.Duration(rand.Intn(1000))
time.Sleep(r * time.Millisecond)
ticker := time.NewTicker(time.Second)
for range ticker.C {
fmt.Printf("%s Starting...\n", time.Now().Format(layoutFormat))
for i := 0; i < *eventsPerSecond; i++ {
if i%multilineRatio == 0 {
// Add timestamp to the begining of the line as multiline starter and append logEntry[0:len(logEntry)-len(layoutFormat)-1], -1 here is because the extra " " after added timestamp.
f.WriteString(time.Now().Format(layoutFormat) + " " +
logEntry[:(len(logEntry)-len(layoutFormat)-1)] + "\n")
} else {
instanceIdstr := strconv.FormatInt(int64(instanceId), 10)
preStr := " line starter" + instanceIdstr + " "
f.WriteString(preStr + logEntry[:(len(logEntry)-len(preStr))] + "\n")
}
}
f.Sync()
fileSize += (*eventsPerSecond) * (*eventSize)
if fileSize >= logTruncateSize {
os.Truncate(curFilePath, 0)
f.Seek(0, 0)
fileSize = 0
}
fmt.Printf("%s Ended.\n", time.Now().Format(layoutFormat))
}
}