antplusbridge/cmd/bridge/log.go
Erik Brakkee 4949beae3e fix: synchronize logs, buffer events channel, exit on goroutine failure
- Add mutex to prevent interleaved log output from concurrent goroutines
- Make logMsg delegate to logPrintf for consistent synchronization
- Buffer events channel to size 1 with select/drop when full
- Close events channel on ListenForTrainer exit so process terminates
2026-05-27 00:36:06 +02:00

24 lines
342 B
Go

package main
import (
"fmt"
"sync"
"time"
)
var logMu sync.Mutex
func logMsg(msg string) {
logPrintf("%s\n", msg)
}
func logPrintf(format string, a ...any) {
logMu.Lock()
fmt.Printf(time.Now().Format("2006-01-02 15:04:05")+" "+format, a...)
logMu.Unlock()
}
func logMsgf(format string, a ...any) {
logPrintf(format+"\n", a...)
}