Skip to content

Commit 63760a7

Browse files
log(envutil): add debug logging to env var parse fallbacks
Add a debug logger to internal/envutil/envutil.go to surface misconfiguration earlier. The logger emits a debug message whenever an environment variable is set but cannot be used (invalid integer, unparseable duration, unrecognized boolean value), helping operators quickly identify why a configured value is being silently ignored. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ca03645 commit 63760a7

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

internal/envutil/envutil.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import (
55
"strconv"
66
"strings"
77
"time"
8+
9+
"github.com/github/gh-aw-mcpg/internal/logger"
810
)
911

12+
var logEnvUtil = logger.New("envutil:envutil")
13+
1014
// GetEnvString returns the value of the environment variable specified by envKey.
1115
// If the environment variable is not set or is empty, it returns the defaultValue.
1216
func GetEnvString(envKey, defaultValue string) string {
@@ -25,6 +29,7 @@ func GetEnvInt(envKey string, defaultValue int) int {
2529
if value, err := strconv.Atoi(envValue); err == nil && value > 0 {
2630
return value
2731
}
32+
logEnvUtil.Printf("GetEnvInt: %s=%q is not a valid positive integer, using default=%d", envKey, envValue, defaultValue)
2833
}
2934
return defaultValue
3035
}
@@ -37,6 +42,7 @@ func GetEnvDuration(envKey string, defaultValue time.Duration) time.Duration {
3742
if d, err := time.ParseDuration(envValue); err == nil && d > 0 {
3843
return d
3944
}
45+
logEnvUtil.Printf("GetEnvDuration: %s=%q is not a valid positive duration, using default=%v", envKey, envValue, defaultValue)
4046
}
4147
return defaultValue
4248
}
@@ -54,6 +60,7 @@ func GetEnvBool(envKey string, defaultValue bool) bool {
5460
case "0", "false", "no", "off":
5561
return false
5662
}
63+
logEnvUtil.Printf("GetEnvBool: %s=%q is not a recognized boolean value, using default=%v", envKey, envValue, defaultValue)
5764
}
5865
return defaultValue
5966
}

0 commit comments

Comments
 (0)