1
0
Fork 0
mirror of https://github.com/chainguard-dev/clog synced 2026-07-06 22:12:46 +00:00

fix: convert WARN string for cloud batch (#76)

### What

Convert WARN string to WARNING for compatibility with Cloud Batch

### Why

We have a service running in Cloud Batch which alerts on any warning
log. Digging into this, it appears Cloud Batch does not convert WARN ->
WARNING and thus interprets the unidentifiable log level as error.

Looking at logs for this service, the `jsonPayload.severity` is removed
for all log levels except for WARN, which ends up interpreted as an
ERROR level:
```
for level in DEBUG INFO WARN WARNING ERROR CRITICAL; do
  count=$(gcloud logging read "resource.type=\"batch.googleapis.com/Job\" labels.component=\"...\" jsonPayload.severity=\"${level}\"" \
    --project=... --limit=1 \
    --format="value(severity)" 2>/dev/null)
  echo "${level} -> ${count:-<no results>}"
done
DEBUG -> <no results>
INFO -> <no results>
WARN -> ERROR
WARNING -> <no results>
ERROR -> <no results>
CRITICAL -> <no results>
```

Signed-off-by: Zackary Crosley <zackary.crosley@chainguard.dev>
This commit is contained in:
Zack Crosley 2026-06-25 15:02:33 -04:00 committed by GitHub
parent e522bdd603
commit 01a02443da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -34,8 +34,14 @@ func NewHandlerForWriter(w io.Writer, level slog.Level) *Handler {
} else if a.Key == slog.LevelKey { } else if a.Key == slog.LevelKey {
a.Key = "severity" a.Key = "severity"
level, ok := a.Value.Any().(slog.Level) level, ok := a.Value.Any().(slog.Level)
if ok && level == LevelCritical { if ok {
a.Value = slog.StringValue("CRITICAL") switch {
case level == LevelCritical:
a.Value = slog.StringValue("CRITICAL")
case level == slog.LevelWarn:
// Convert WARN -> WARNING for Cloud Batch
a.Value = slog.StringValue("WARNING")
}
} }
} }
return a return a