Documentation
¶
Index ¶
- Constants
- Variables
- func Component(parent *slog.Logger, kind, value, name string) *slog.Logger
- func DiscardLogger() *slog.Logger
- func GetLogger(level slog.Level, args ...any) *slog.Logger
- func NewLogger(store store.Store[any], args ...any) *slog.Logger
- func NewTest(t TestLogf) *slog.Logger
- func Redact(s string) string
- func RedactedJSON(v any, fields ...string) string
- func RedactedValue(v any, fields ...string) slog.Value
- func StdLogger(l *slog.Logger, level slog.Level) *log.Logger
- type Flags
- type FlagsProvider
- type TestLogf
Constants ¶
const RedactedPlaceholder = "***"
RedactedPlaceholder is the value substituted for any non-empty secret when a redacted view of a config is produced.
Variables ¶
var DefaultSecretFields = []string{
"password",
"token",
"auth-token",
"client-secret",
"clientsecret",
"bearer",
"secret",
"api-key",
"apikey",
"credentials",
}
DefaultSecretFields lists JSON keys that are treated as secrets by RedactedJSON when no explicit list is provided. Matching is case-insensitive against the lowercase form of the key.
Functions ¶
func Component ¶ added in v0.46.0
Component returns a child logger annotated with the component kind and instance name. If parent is nil, a discard logger is returned so callers can use the result unconditionally.
The kind argument is used both as the attribute key and the attribute value, e.g. Component(l, "output", "file", "f1") yields output=file name=f1. Common kinds: "output", "input", "processor", "cache", "locker", "loader", "action".
func DiscardLogger ¶ added in v0.46.0
DiscardLogger returns a slog.Logger that discards all records.
func NewTest ¶ added in v0.46.0
NewTest returns a slog.Logger that forwards every record to t.Logf at LevelDebug or above. Useful for tests that want logger output captured alongside other test output.
func Redact ¶ added in v0.46.0
Redact returns "***" when s is non-empty, and "" otherwise. Centralising this lets us change the placeholder in one place and avoids accidental "***" leakage when a secret was never set.
func RedactedJSON ¶ added in v0.46.0
RedactedJSON marshals v to JSON and replaces the values of any string fields whose key (case-insensitive) appears in fields with "***". If fields is empty, DefaultSecretFields is used. Non-string values keyed by a secret name are left untouched (this avoids surprising shape changes for typed numeric or bool fields). On error, an empty string is returned so callers can use it directly in log lines.
func RedactedValue ¶ added in v0.46.0
RedactedValue returns v's JSON representation with configured secret fields redacted. Types that can contain credentials can use this from LogValue to make slog.Any("config", v) safe by default.
Types ¶
type Flags ¶ added in v0.46.0
type Flags struct {
Log bool
Debug bool
LogFile string
LogMaxSize int
LogMaxBackups int
LogCompress bool
}
Flags carries the subset of configuration values needed to build the application logger. It is a value type so callers can construct it directly without sharing pointers.
type FlagsProvider ¶ added in v0.46.0
type FlagsProvider interface {
LoggingFlags() Flags
}
FlagsProvider is implemented by types that expose logging Flags. Configuration types implement this interface so the logging package can construct a logger without depending on the config package.