feat(cmd/joj3): more random runID
All checks were successful
submodules sync / sync (push) Successful in 47s
build / build (push) Successful in 1m41s
build / trigger-build-image (push) Successful in 9s

This commit is contained in:
张泊明518370910136 2024-11-12 03:09:10 -05:00
parent e4bfcfbe8d
commit ea75e992aa
GPG Key ID: D47306D7062CDA9D

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"log/slog" "log/slog"
"os" "os"
"strconv"
"time" "time"
) )
@ -18,9 +17,16 @@ type multiHandler struct {
var runID string var runID string
func init() { func init() {
runID = fmt.Sprintf("%06s%04s", timestamp := time.Now().UnixNano()
strconv.FormatInt(time.Now().Unix(), 36), pid := os.Getpid()
strconv.FormatInt(int64(os.Getpid()), 36)) 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 { func (h *multiHandler) Enabled(ctx context.Context, level slog.Level) bool {