Skip to content

Commit d723006

Browse files
committed
grpclog: skip unrecognized component log levels instead of defaulting to fatal
1 parent f566320 commit d723006

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

grpclog/component.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ func Component(componentName string) DepthLoggerV2 {
164164
c.errorDepth = func(depth int, args ...any) {
165165
componentErrorDepth(depth+1, args...)
166166
}
167-
case severityFatal:
168-
c.infoDepth = noopDepth
169-
c.warningDepth = noopDepth
170-
c.errorDepth = noopDepth
171167
}
172168
}
173169

grpclog/component_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,9 @@ func TestParseComponentLogLevel(t *testing.T) {
6969
},
7070
},
7171
{
72-
name: "mixed-case level names are treated as unknown and default to FATAL",
72+
name: "mixed-case level names are treated as unknown and skipped",
7373
input: "dns:Error,xds:Warning,authz:Info",
74-
want: map[string]severityLevel{
75-
"dns": severityFatal,
76-
"xds": severityFatal,
77-
"authz": severityFatal,
78-
},
74+
want: map[string]severityLevel{},
7975
},
8076
{
8177
name: "parses multiple comma-separated components with different levels",
@@ -102,10 +98,9 @@ func TestParseComponentLogLevel(t *testing.T) {
10298
},
10399
},
104100
{
105-
name: "unrecognized level name defaults to FATAL",
101+
name: "unrecognized level name is skipped",
106102
input: "dns:UNKNOWN,xds:ERROR",
107103
want: map[string]severityLevel{
108-
"dns": severityFatal,
109104
"xds": severityError,
110105
},
111106
},
@@ -220,11 +215,14 @@ func TestLogger(t *testing.T) {
220215
},
221216
},
222217
{
223-
name: "FATAL GRPC_GO_COMPONENT_LOG_LEVEL suppresses all non-fatal logs",
218+
name: "unrecognized GRPC_GO_COMPONENT_LOG_LEVEL falls back to global default",
224219
componentLogLevel: "dns:FATAL",
225220
logSeverityLevel: "INFO",
226221
components: []string{"dns", "balancer"},
227222
want: []string{
223+
"INFO: [dns] dns-info",
224+
"WARNING: [dns] dns-warning",
225+
"ERROR: [dns] dns-error",
228226
"INFO: [balancer] balancer-info",
229227
"WARNING: [balancer] balancer-warning",
230228
"ERROR: [balancer] balancer-error",

grpclog/grpclog.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const (
5858
severityInfo severityLevel = iota
5959
severityWarning
6060
severityError
61-
severityFatal
6261
)
6362

6463
func parseComponentLogLevels(logLevel string) map[string]severityLevel {
@@ -85,7 +84,7 @@ func parseComponentLogLevels(logLevel string) map[string]severityLevel {
8584
case "ERROR", "error":
8685
logLevels[component] = severityError
8786
default:
88-
logLevels[component] = severityFatal
87+
continue
8988
}
9089
}
9190
return logLevels

0 commit comments

Comments
 (0)