تخطَّ إلى المحتوى

Structured Logging (ARCH5158)

هذا المحتوى غير متوفر بلغتك بعد.

Key go.logging.structured-logging · Severity warning · Category logging

Embedding variables into a log message via string concatenation hurts log aggregation and filtering. Structured key/value pairs keep the message stable and make the data queryable.

func login(log *slog.Logger, user string, attempt int) {
log.Info("login for " + user + " attempt " + strconv.Itoa(attempt))
}
func login(log *slog.Logger, user string, attempt int) {
log.Info("login attempt", "user", user, "attempt", attempt)
}

Use a constant message text and pass variables as separate key/value fields.