forked from baron/baron-sso
make dev/dev-debug 구분.
This commit is contained in:
@@ -37,20 +37,25 @@ func IsProductionEnv(appEnv string) bool {
|
||||
return IsProductionLikeEnv(appEnv)
|
||||
}
|
||||
|
||||
func parseBoolFlag(raw string) bool {
|
||||
func parseOptionalBoolFlag(raw string) (bool, bool) {
|
||||
switch strings.ToLower(strings.TrimSpace(raw)) {
|
||||
case "1", "true", "yes", "y", "on":
|
||||
return true
|
||||
return true, true
|
||||
case "0", "false", "no", "n", "off":
|
||||
return false, true
|
||||
default:
|
||||
return false
|
||||
return false, false
|
||||
}
|
||||
}
|
||||
|
||||
func ClientDebugEnabled(appEnv, productionDebugFlag string) bool {
|
||||
func ClientDebugEnabled(appEnv, debugFlag string) bool {
|
||||
if enabled, ok := parseOptionalBoolFlag(debugFlag); ok {
|
||||
return enabled
|
||||
}
|
||||
if !IsProductionEnv(appEnv) {
|
||||
return true
|
||||
}
|
||||
return parseBoolFlag(productionDebugFlag)
|
||||
return false
|
||||
}
|
||||
|
||||
func NormalizeClientLogLevel(level string) slog.Level {
|
||||
|
||||
@@ -9,7 +9,14 @@ import (
|
||||
func TestClientDebugEnabled(t *testing.T) {
|
||||
t.Run("non production enables debug by default", func(t *testing.T) {
|
||||
assert.True(t, ClientDebugEnabled("dev", ""))
|
||||
assert.True(t, ClientDebugEnabled("local", "false"))
|
||||
assert.True(t, ClientDebugEnabled("local", ""))
|
||||
})
|
||||
|
||||
t.Run("explicit debug flag applies in non production", func(t *testing.T) {
|
||||
assert.True(t, ClientDebugEnabled("dev", "true"))
|
||||
assert.True(t, ClientDebugEnabled("local", "1"))
|
||||
assert.False(t, ClientDebugEnabled("dev", "false"))
|
||||
assert.False(t, ClientDebugEnabled("local", "0"))
|
||||
})
|
||||
|
||||
t.Run("production disables debug by default", func(t *testing.T) {
|
||||
@@ -37,6 +44,8 @@ func TestShouldAcceptClientLog(t *testing.T) {
|
||||
assert.True(t, ShouldAcceptClientLog("stage", "", "ERROR"))
|
||||
assert.True(t, ShouldAcceptClientLog("production", "true", "INFO"))
|
||||
assert.True(t, ShouldAcceptClientLog("dev", "", "INFO"))
|
||||
assert.False(t, ShouldAcceptClientLog("dev", "false", "INFO"))
|
||||
assert.True(t, ShouldAcceptClientLog("dev", "false", "WARN"))
|
||||
}
|
||||
|
||||
func TestShouldFilterNoisyClientInfo(t *testing.T) {
|
||||
@@ -44,6 +53,7 @@ func TestShouldFilterNoisyClientInfo(t *testing.T) {
|
||||
assert.True(t, ShouldFilterNoisyClientInfo("stage", "", "Navigating to /ko/signin"))
|
||||
assert.False(t, ShouldFilterNoisyClientInfo("production", "true", "Navigating to /ko/signin"))
|
||||
assert.False(t, ShouldFilterNoisyClientInfo("dev", "", "Navigating to /ko/signin"))
|
||||
assert.True(t, ShouldFilterNoisyClientInfo("dev", "false", "Navigating to /ko/signin"))
|
||||
}
|
||||
|
||||
func TestSanitizeClientLogData(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user