logx

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultMaxLogBytes = 20 << 20

DefaultMaxLogBytes is the size at which a log file is rotated.

View Source
const MaxPayloadLogBytes = 512

MaxPayloadLogBytes is the length a payload's logged text is truncated to.

Variables

This section is empty.

Functions

func Payload

func Payload(key string, b []byte) slog.Attr

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.

func (*RotatingFile) Close

func (r *RotatingFile) Close() error

Close closes the file.

func (*RotatingFile) Write

func (r *RotatingFile) Write(p []byte) (int, error)

Write appends p to the log file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL