Skip to content

Commit eda7bc4

Browse files
chris-rockclaude
andcommitted
Rename gcpLevelEncoder to severityLevelEncoder for cloud-agnostic naming
Update comments to reference all major cloud providers (GKE, AKS, EKS) instead of just GCP/GKE. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8406549 commit eda7bc4

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

pkg/utils/logger/logger.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1010
)
1111

12-
// gcpLevelEncoder encodes log levels to Google Cloud Logging severity names.
13-
// GCP expects "WARNING" instead of zap's "WARN", and maps DPANIC/PANIC/FATAL to CRITICAL.
14-
func gcpLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
12+
// severityLevelEncoder encodes log levels to cloud-compatible severity names.
13+
// Uses "WARNING" instead of zap's "WARN", and maps DPANIC/PANIC/FATAL to CRITICAL.
14+
func severityLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
1515
switch level {
1616
case zapcore.WarnLevel:
1717
enc.AppendString("WARNING")
@@ -24,18 +24,18 @@ func gcpLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
2424

2525
func NewLogger() logr.Logger {
2626
opts := zap.Options{
27-
// Use production mode by default for JSON output (required for GKE log parsing).
27+
// Use production mode for JSON output (enables structured logging in cloud environments).
2828
// Can be overridden with --zap-devel flag for local development.
2929
Development: false,
3030
StacktraceLevel: zapcore.DPanicLevel,
3131
TimeEncoder: zapcore.RFC3339TimeEncoder,
32-
// Configure encoder for GCP/GKE compatibility:
33-
// - Use "severity" instead of "level" for log level field
34-
// - Use GCP-compatible level names (WARNING instead of WARN)
32+
// Configure encoder for cloud logging compatibility:
33+
// - Use "severity" field name (recognized by GKE, AKS, EKS log explorers)
34+
// - Use standard severity names (WARNING instead of WARN, CRITICAL for fatal errors)
3535
EncoderConfigOptions: []zap.EncoderConfigOption{
3636
func(ec *zapcore.EncoderConfig) {
3737
ec.LevelKey = "severity"
38-
ec.EncodeLevel = gcpLevelEncoder
38+
ec.EncodeLevel = severityLevelEncoder
3939
},
4040
},
4141
}

pkg/utils/logger/logger_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ func (t *testEncoder) AppendUint16(uint16) {}
3737
func (t *testEncoder) AppendUint8(uint8) {}
3838
func (t *testEncoder) AppendUintptr(uintptr) {}
3939

40-
func TestGcpLevelEncoder(t *testing.T) {
40+
func TestSeverityLevelEncoder(t *testing.T) {
4141
tests := []struct {
4242
level zapcore.Level
4343
expected string
4444
}{
4545
{zapcore.DebugLevel, "DEBUG"},
4646
{zapcore.InfoLevel, "INFO"},
47-
{zapcore.WarnLevel, "WARNING"}, // GCP expects WARNING, not WARN
47+
{zapcore.WarnLevel, "WARNING"}, // Cloud log explorers expect WARNING, not WARN
4848
{zapcore.ErrorLevel, "ERROR"},
4949
{zapcore.DPanicLevel, "CRITICAL"},
5050
{zapcore.PanicLevel, "CRITICAL"},
@@ -54,7 +54,7 @@ func TestGcpLevelEncoder(t *testing.T) {
5454
for _, tt := range tests {
5555
t.Run(tt.level.String(), func(t *testing.T) {
5656
enc := &testEncoder{}
57-
gcpLevelEncoder(tt.level, enc)
57+
severityLevelEncoder(tt.level, enc)
5858
assert.Equal(t, tt.expected, enc.result)
5959
})
6060
}

0 commit comments

Comments
 (0)