Documentation
¶
Overview ¶
Package logx provides lazy, redacted, truncated slog attributes for hot-path logging. A raw request or response payload must never reach a log file unredacted, and formatting it (converting bytes to a string, scanning for secrets) must never cost anything unless the record is actually going to be emitted.
Index ¶
Constants ¶
const DefaultMaxLogBytes = 20 << 20
DefaultMaxLogBytes is the size at which a log file is rotated.
const MaxPayloadLogBytes = 512
MaxPayloadLogBytes is the length a payload's logged text is truncated to.
Variables ¶
This section is empty.
Functions ¶
func Payload ¶
Payload returns a slog.Attr for a raw byte payload (a request's params, a response's result, an upstream line) whose value is redacted and truncated, and only when the log record is actually emitted:
logger.Debug("handleToolsCall called", logx.Payload("params", req.Params))
Building the Attr itself does no work beyond holding a reference to b, so it is safe to call regardless of the configured log level.
Types ¶
type RotatingFile ¶
type RotatingFile struct {
// contains filtered or unexported fields
}
RotatingFile is an append-only log file that never grows past about maxBytes: when it does, it is renamed to "<path>.1" (replacing the previous one) and a new file is started. So a log takes at most about twice maxBytes on disk, however long the process runs.
Several processes may log to the same path (one `server run --stdio` per MCP client): each notices when another rotated the file and follows it to the new one.
func OpenRotating ¶
func OpenRotating(path string, maxBytes int64) (*RotatingFile, error)
OpenRotating opens (creating if needed, mode 0600) the log file at path. A non-positive maxBytes means DefaultMaxLogBytes.