Structured Logging (ARCH5158)
Esta página aún no está disponible en tu idioma.
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.
Incorrect
Section titled “Incorrect”func login(log *slog.Logger, user string, attempt int) { log.Info("login for " + user + " attempt " + strconv.Itoa(attempt))}Correct
Section titled “Correct”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.