in cmd/emf-generator/emf-generator.go [47:71]
func writeStructuredLog(fileIndex int) {
eventSize := len(structuredLogEvent) + len(strconv.FormatInt(makeTimestamp(), 10)) - 2
curFilePath := path.Join(*structuredLogDir, fmt.Sprintf("%s%d.json", *filePrefix, fileIndex))
fmt.Printf("Creating file %s\n", curFilePath)
os.MkdirAll(*structuredLogDir, 0755)
sf, _ := 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 {
for i := 0; i < *eventsPerSecond; i++ {
sf.WriteString(fmt.Sprintf(structuredLogEvent+"\n", makeTimestamp()))
}
sf.Sync()
fileSize += (*eventsPerSecond) * (eventSize)
if fileSize >= logTruncateSize {
os.Truncate(curFilePath, 0)
sf.Seek(0, 0)
fileSize = 0
}
}
}