diff --git a/cli.go b/cli.go index cf0e5f3..3a28d63 100644 --- a/cli.go +++ b/cli.go @@ -260,10 +260,12 @@ func PluralExt(i int, noun string, ext string) string { // Kubernetes for instance sends a SIGTERM before killing a pod. // You can place your clean shutdown code after this call in the main(). // This assumes there is another go routine doing something (like a server). +// Using this implies there should be another goroutine at least, so you need to put +// back goroutine logging (vs what log.SetDefaultsForClientTools() does) by calling +// this before starting any other goroutine so there is no race condition: +// +// log.Config.GoroutineID = true func UntilInterrupted() { - // if UntilInterrupted is called, it implies there should be another goroutine at least. - // so we put back that logging (vs what log.SetDefaultsForClientTools() does). - log.Config.GoroutineID = true // listen for interrupt signal c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) diff --git a/go.mod b/go.mod index e044878..8e7c8e6 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( fortio.org/duration v1.0.4 - fortio.org/log v1.17.2 + fortio.org/log v1.18.0 fortio.org/version v1.0.4 golang.org/x/crypto/x509roots/fallback v0.0.0-20250203165127-fa5273e46196 ) diff --git a/go.sum b/go.sum index 79a7666..30a7af7 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ fortio.org/duration v1.0.4 h1:TB07ng4UsMZPDRujJRkTJIcNqMTLM283zob10nb9K24= fortio.org/duration v1.0.4/go.mod h1:RuBVqdcCKRwMmI8WIdVq8kd7ngQPCIe6G7AU0NC0XDw= -fortio.org/log v1.17.2 h1:JPX/ApDXDoGzsNtXw0AJI4ai6tl9wHp4Ch6bVs1OK0Y= -fortio.org/log v1.17.2/go.mod h1:1V7bPfFI7ZVTdtN9DnUCAN0ilEMs5VgKjHIDRO7Mjzk= +fortio.org/log v1.18.0 h1:mB7gg5AWvcyPUQ0dA6CSUGarX/2rEkv0yWZdARfOdEQ= +fortio.org/log v1.18.0/go.mod h1:1V7bPfFI7ZVTdtN9DnUCAN0ilEMs5VgKjHIDRO7Mjzk= fortio.org/struct2env v0.4.2 h1:Xh7HlS9vf2ZdRvRfmoGIasNDO8t6z36M713utVODRCo= fortio.org/struct2env v0.4.2/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410= fortio.org/version v1.0.4 h1:FWUMpJ+hVTNc4RhvvOJzb0xesrlRmG/a+D6bjbQ4+5U= diff --git a/sampleTool/main.go b/sampleTool/main.go index 54759f8..fefc52e 100644 --- a/sampleTool/main.go +++ b/sampleTool/main.go @@ -26,6 +26,7 @@ func main() { log.Attr("num_args", len(flag.Args())), log.Attr("args", flag.Args())) if *doWait { + log.Config.GoroutineID = true // need to do that _before_ starting other goroutines to get correct logging log.Infof("Waiting for ^C (or kill) to exit") cli.UntilInterrupted() log.Infof("Now done...")