logutil

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 17 Imported by: 1 module, 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 logutil writes the llm-proxy full log.

Two properties matter more than formatting:

  • A request must never block on disk. Writes go through a bounded queue and a single writer goroutine, so a multi-megabyte request body cannot hold the request path behind a mutex or a slow filesystem.
  • A multi-megabyte body must not land in the log by default. Body lines are reduced to size + digest unless the body is small or --log-body=full is set; the log stays greppable and stops growing at hundreds of megabytes per hour.

Rotation keeps its existing contract: hourly segments named <path>.<YYYYMMDDHH>, <path> itself a symlink to the current segment, and the previous hour retained. The queue's writer goroutine owns rotation so a buffered line can never spill into the next hour's segment.

Index

Constants

View Source
const (

	// DefaultBodyLimit is the largest body logged verbatim in digest mode.
	DefaultBodyLimit = 64 << 10 // 64 KiB
	// DefaultBufferSize is the bufio buffer between the queue and the file.
	DefaultBufferSize = 256 << 10 // 256 KiB
	// DefaultQueueSize bounds bytes waiting in memory for the writer.
	DefaultQueueSize = 4 << 20 // 4 MiB
	// DefaultFlushEvery bounds how long a line may sit in the buffer.
	DefaultFlushEvery = 250 * time.Millisecond
)
View Source
const DefaultLogFile = "/tmp/llm-proxy.log"

DefaultLogFile is the full-log destination used when --log is not passed.

View Source
const LogOff = "off"

LogOff is the --log value that disables file logging entirely.

Variables

This section is empty.

Functions

func Configure added in v0.0.37

func Configure(opts Options)

Configure sets the process-wide options used by OpenAppend. The CLI calls it once after flag parsing; concurrent proxy modes then share one policy.

func ExpandPath

func ExpandPath(path string) (string, error)

func FormatBytes added in v0.0.37

func FormatBytes(n uint64) string

FormatBytes renders a byte count for notices and warnings.

func LogHeaders

func LogHeaders(headers http.Header, logf func(format string, args ...any))

func ParseBytes added in v0.0.37

func ParseBytes(value string) (int, error)

ParseBytes parses a byte size: a plain integer, or a suffix from B, K/KB/KiB, M/MB/MiB, G/GB/GiB (case-insensitive, binary multiples).

func RedactHeaderValue

func RedactHeaderValue(key string, values []string) string

func ResolveLogFile added in v0.0.12

func ResolveLogFile(flagValue string) (path string, defaulted bool)

ResolveLogFile maps the --log flag value to the file to open. It returns the resolved path and whether the default was applied (so the caller can print a notice). A false resolved value means no file logging.

Types

type BodyMode added in v0.0.37

type BodyMode string

BodyMode selects what a body line keeps.

const (
	// BodyDigest logs bodies up to Options.BodyLimit verbatim and larger ones
	// as size + sha256.
	BodyDigest BodyMode = "digest"
	// BodyFull logs every body verbatim (the pre-existing behavior).
	BodyFull BodyMode = "full"
	// BodyOff logs no body content at all, only size + sha256.
	BodyOff BodyMode = "off"
)

func ParseBodyMode added in v0.0.37

func ParseBodyMode(value string) (BodyMode, error)

ParseBodyMode validates a --log-body value.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger writes formatted lines and body lines to one sink.

func New

func New(w io.Writer) *Logger

New wraps w with the default body policy; the writer is used synchronously. OpenAppend is the asynchronous, rotating entry point used by the proxies.

func OpenAppend

func OpenAppend(path string) (*Logger, io.Closer, error)

OpenAppend opens an asynchronous, hourly-rotated log using the process-wide options. A nil Logger means file logging is disabled.

func OpenAppendWith added in v0.0.37

func OpenAppendWith(path string, opts Options) (*Logger, io.Closer, error)

OpenAppendWith is OpenAppend with explicit options.

func (*Logger) Body added in v0.0.37

func (l *Logger) Body(label string, body []byte)

Body writes one body line. The body is kept verbatim only when the mode and size allow it; otherwise the line carries size and digest instead.

func (*Logger) BodyString added in v0.0.37

func (l *Logger) BodyString(label, body string)

BodyString is Body for an already-decoded string.

func (*Logger) LogHeaders

func (l *Logger) LogHeaders(headers http.Header)

func (*Logger) Printf

func (l *Logger) Printf(format string, args ...any)

Printf writes one timestamped line.

type Options added in v0.0.37

type Options struct {
	BodyMode   BodyMode
	BodyLimit  int
	BufferSize int
	QueueSize  int
	FlushEvery time.Duration
}

Options configures one log sink.

func CurrentOptions added in v0.0.37

func CurrentOptions() Options

CurrentOptions reports the process-wide options.

func DefaultOptions added in v0.0.37

func DefaultOptions() Options

DefaultOptions is the configuration used when the CLI passes no log flags.

func OptionsFromFlags added in v0.0.37

func OptionsFromFlags(bodyMode, bodyLimit, queueSize string) (Options, error)

OptionsFromFlags resolves the three --log-* flag values into Options.

Jump to

Keyboard shortcuts

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