blob: 7f91ae8185c3de97da3999da7b1608b420c4ab71 [file] [edit]
package blog
// This file contains helper functions that can be used throughout the boulder
// code base to ensure that certain commonly-logged values always have the same
// key name and value type. This prevents situations like sometimes calling the
// requesting account "requester" or "acct" or "regID"; or sometimes logging the
// authz ID as an integer and sometimes as a string.
//
// Any time we find ourselves logging the same slog.Attr from 3+ files we
// should consider adding a helper here instead.
//
// Note that several other attr keys are reserved and should not be used:
// - "time": used by the slog package
// - "level": used by the slog package
// - "msg": used by the slog package
// - "source": used by the slog package
// - "error": used by our blog.Error and blog.AuditError helpers
// - "audit": used by our blog.AuditError and blog.AuditInfo helpers
import (
"fmt"
"log/slog"
"github.com/letsencrypt/boulder/identifier"
)
// Acct returns a slog.Attr whose key is "acct" and whose value is the unique
// numeric ID of the account.
func Acct(acctID int64) slog.Attr {
return slog.Int64("acct", acctID)
}
// Order returns a slog.Attr whose key is "order" and whose value is the unique
// numeric ID of the order.
func Order(orderID int64) slog.Attr {
return slog.Int64("order", orderID)
}
// Authz returns a slog.Attr whose key is "authz" and whose value is the unique
// numeric ID of the authz.
func Authz(authzID int64) slog.Attr {
return slog.Int64("authz", authzID)
}
// Serial returns a slog.Attr whose key is "serial" and whose value is the
// given string. The argument should be hex-encoded.
func Serial(serial string) slog.Attr {
return slog.String("serial", serial)
}
// MTCLogID returns a slog.Attr whose key is "mtclogid" and whose value is the
// given string, which should be the log's relative OID.
func MTCLogID(mtcLogID string) slog.Attr {
return slog.String("mtclogid", mtcLogID)
}
// MTCSerial returns a slog.Attr whose key is "serial" and whose value is the
// hex encoding of the given uint64.
func MTCSerial(serial uint64) slog.Attr {
return slog.String("serial", fmt.Sprintf("%016x", serial))
}
// Idents returns a slog.Attr whose key is "idents" and whose value is a list
// of the given identifiers.
func Idents(idents ...identifier.ACMEIdentifier) slog.Attr {
return slog.Any("idents", idents)
}
// Error returns a slog.Attr whose key is "error" and whose value is the value
// from err.Error(). This attribute is used automatically by methods that log
// at the error level, like blog.Logger.AuditError().
func Error(err error) slog.Attr {
return slog.String("error", err.Error())
}