LogRoutine

Jmnote (토론 | 기여)님의 2024년 8월 12일 (월) 23:27 판 (→‎개요)

개요

LogGen
package main

import (
	"fmt"
	"os"
	"strconv"
	"sync"
	"time"

	"github.com/google/uuid"
)

func generateLog(wg *sync.WaitGroup, batchID string, logIndex int) {
	defer wg.Done()
	fmt.Printf("LogGen BatchID: %s, LogIndex: %d\n", batchID, logIndex)
}

func main() {
	startTime := time.Now()
	var wg sync.WaitGroup

	numLogs := 10
	if envNumLogs, exists := os.LookupEnv("NUM_LOGS"); exists {
		if parsedNumLogs, err := strconv.Atoi(envNumLogs); err == nil {
			numLogs = parsedNumLogs
		} else {
			fmt.Printf("Invalid NUM_LOGS value, using default: %d\n", numLogs)
		}
	}

	batchID := uuid.New().String()[:8]
	fmt.Printf("LogGen start: %s\n", startTime.Format(time.RFC3339))

	for i := 1; i <= numLogs; i++ {
		wg.Add(1)
		go generateLog(&wg, batchID, i)
	}
	wg.Wait()

	elapsedTime := time.Since(startTime)
	fmt.Printf("LogGen end: %s\n", time.Now().Format(time.RFC3339))
	fmt.Printf("LogGen Elapsed Time: %s\n", elapsedTime)
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}