Logging Errors Effectively

Updated

October 31, 2026

Logging Errors Effectively

Structured logging to standard error:

log() {
    local level="$1"; shift
    local ts
    ts=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
    printf '{"time":"%s","level":"%s","message":"%s"}\n' "$ts" "$level" "$*" >&2
}

log INFO "Service initialization started"
log ERROR "Database connection timeout"