Documentation
¶
Overview ¶
Package logx is the application logger: log/slog, with the request-scoped identity from ctxkit attached automatically.
There is one rule worth stating. Log the CAUSE, never the response. An *errs.Error carries a caller-safe Message and an internal Cause; the client gets the first, this package gets both. Logging only what you returned is how a production incident becomes a trace id with no explanation behind it.
Index ¶
- func C(ctx context.Context) *slog.Logger
- func Err(ctx context.Context, msg string, err error, args ...any)
- func From(ctx context.Context) *slog.Logger
- func Into(ctx context.Context, l *slog.Logger) context.Context
- func New(opts Options) *slog.Logger
- func ParseLevel(s string) slog.Level
- type Format
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func C ¶
C returns the context logger with the request-scoped identity attached: trace id, request id, account and user when present.
Use it at the point of logging — `logx.C(ctx).Warn(...)` — rather than building a decorated logger and passing it around.
func Err ¶
Err logs an error with everything the client did not get: the kind, the code, the internal cause and the structured meta.
It is the counterpart of the web layer's sanitised response — between the two, every failure is both safe on the wire and fully explained in the log.
func Into ¶
Into returns a context carrying l, so a deep call can log with the request's own fields without threading a logger through every signature.
func ParseLevel ¶
ParseLevel maps a config string ("debug", "info", "warn", "error") to a slog.Level, defaulting to Info for anything unrecognised.
Types ¶
type Options ¶
type Options struct {
Level slog.Level
Format Format
// Writer defaults to os.Stdout. Logs go to stdout, not stderr: stderr is
// for the process dying, and mixing the two makes a crash hard to find.
Writer io.Writer
// Service is attached to every record as "service".
Service string
// AddSource includes file:line. Costs a little; worth it outside hot loops.
AddSource bool
}
Options configures a logger.