From 3a2b3d1312aad798d3585eaaa6eb28d97e03934f Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Wed, 3 Apr 2024 09:55:56 -0400
Subject: [PATCH] feat(echo): set log level according to env
Set the log level according to the value of YGG_LOG_LEVEL.
Print the worker's environment when run at level Debug or higher.
Signed-off-by: Link Dupont
---
worker/echo/main.go | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/worker/echo/main.go b/worker/echo/main.go
index 270ae7e3..68f0e24d 100644
--- a/worker/echo/main.go
+++ b/worker/echo/main.go
@@ -16,6 +16,16 @@ import (
var yggdDispatchSocketAddr string
func main() {
+ // Set log level inherited from the environment
+ if logLevel, ok := os.LookupEnv("YGG_LOG_LEVEL"); ok {
+ level, err := log.ParseLevel(logLevel)
+ if err != nil {
+ log.Fatalf("cannot parse log level: %v", err)
+ }
+ log.SetLevel(level)
+ }
+ log.Debugf("current environment: %v", os.Environ())
+
// Get initialization values from the environment.
var ok bool
yggdDispatchSocketAddr, ok = os.LookupEnv("YGG_SOCKET_ADDR")