Skip to content

Commit e0ccf72

Browse files
authored
fix tracing enabled when log level is LogLevelNone (#115)
1 parent 2b9d0ed commit e0ccf72

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func NewProtobufClient(endpoint string, config Config) *Client {
8888
}
8989

9090
func (c *Client) logLevelEnabled(level LogLevel) bool {
91-
return level >= c.config.LogLevel
91+
return c.config.LogLevel > LogLevelNone && level >= c.config.LogLevel
9292
}
9393

9494
func (c *Client) log(level LogLevel, message string, fields map[string]string) {

client_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,3 +649,56 @@ func TestHandlePublishFossil(t *testing.T) {
649649
testFossil(t, client)
650650
})
651651
}
652+
653+
func TestLogLevel(t *testing.T) {
654+
cases := []struct {
655+
name string
656+
configuredLevel LogLevel
657+
requestedLevel LogLevel
658+
enabled bool
659+
}{
660+
{
661+
"configured with debug, requested trace",
662+
LogLevelDebug,
663+
LogLevelTrace,
664+
false,
665+
},
666+
{
667+
"configured with none, requested trace",
668+
LogLevelNone,
669+
LogLevelTrace,
670+
false,
671+
},
672+
{
673+
"configured with none, requested dabug",
674+
LogLevelNone,
675+
LogLevelDebug,
676+
false,
677+
},
678+
{
679+
"configured with trace, requested debug",
680+
LogLevelTrace,
681+
LogLevelDebug,
682+
true,
683+
},
684+
{
685+
"configured with debug, requested debug",
686+
LogLevelDebug,
687+
LogLevelDebug,
688+
true,
689+
},
690+
}
691+
692+
for _, tc := range cases {
693+
t.Run(tc.name, func(t *testing.T) {
694+
client := NewJsonClient("ws://localhost:9000/connection/websocket", Config{
695+
LogLevel: tc.configuredLevel,
696+
})
697+
698+
got := client.logLevelEnabled(tc.requestedLevel)
699+
if got != tc.enabled {
700+
t.Errorf("expected %v got %v", tc.enabled, got)
701+
}
702+
})
703+
}
704+
}

0 commit comments

Comments
 (0)