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
- func Configure(opts Options)
- func ExpandPath(path string) (string, error)
- func FormatBytes(n uint64) string
- func LogHeaders(headers http.Header, logf func(format string, args ...any))
- func ParseBytes(value string) (int, error)
- func RedactHeaderValue(key string, values []string) string
- func ResolveLogFile(flagValue string) (path string, defaulted bool)
- type BodyMode
- type Logger
- type Options
Constants ¶
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 )
const DefaultLogFile = "/tmp/llm-proxy.log"
DefaultLogFile is the full-log destination used when --log is not passed.
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 FormatBytes ¶ added in v0.0.37
FormatBytes renders a byte count for notices and warnings.
func ParseBytes ¶ added in v0.0.37
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 ResolveLogFile ¶ added in v0.0.12
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
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 ¶
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 ¶
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
OpenAppendWith is OpenAppend with explicit options.
func (*Logger) Body ¶ added in v0.0.37
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
BodyString is Body for an already-decoded string.
func (*Logger) LogHeaders ¶
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
OptionsFromFlags resolves the three --log-* flag values into Options.