From ea75e992aab25fdaee98bce0e87d9e8033d2cd8b Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Tue, 12 Nov 2024 03:09:10 -0500 Subject: [PATCH] feat(cmd/joj3): more random runID --- cmd/joj3/log.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/joj3/log.go b/cmd/joj3/log.go index 5ced112..94065a8 100644 --- a/cmd/joj3/log.go +++ b/cmd/joj3/log.go @@ -5,7 +5,6 @@ import ( "fmt" "log/slog" "os" - "strconv" "time" ) @@ -18,9 +17,16 @@ type multiHandler struct { var runID string func init() { - runID = fmt.Sprintf("%06s%04s", - strconv.FormatInt(time.Now().Unix(), 36), - strconv.FormatInt(int64(os.Getpid()), 36)) + timestamp := time.Now().UnixNano() + pid := os.Getpid() + high := timestamp >> 32 + low := timestamp & 0xFFFFFFFF + combined := high ^ low + combined ^= int64(pid) + combined ^= int64(timestamp >> 16) + combined ^= (combined >> 8) + combined ^= (combined << 16) + runID = fmt.Sprintf("%08X", combined&0xFFFFFFFF) } func (h *multiHandler) Enabled(ctx context.Context, level slog.Level) bool {