filch

package
v1.94.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: BSD-3-Clause Imports: 12 Imported by: 14

Documentation

Overview

Package filch is a file system queue that pilfers your stderr. (A FILe CHannel that filches.)

Index

Constants

View Source
const DefaultMaxFileSize = 50 << 20
View Source
const DefaultMaxLineSize = 64 << 10

Variables

This section is empty.

Functions

This section is empty.

Types

type Filch

type Filch struct {
	// OrigStderr is the original [os.Stderr] if [Options.ReplaceStderr] is specified.
	// Writing directly to this avoids writing into the Filch buffer.
	// Otherwise, it is nil.
	OrigStderr *os.File
	// contains filtered or unexported fields
}

A Filch uses two alternating files as a simplistic ring buffer.

func New

func New(filePrefix string, opts Options) (f *Filch, err error)

New creates a new filch around two log files, each starting with filePrefix.

func (*Filch) Close

func (f *Filch) Close() error

Close closes the Filch, releasing all resources.

func (*Filch) ExpVar added in v1.94.0

func (f *Filch) ExpVar() expvar.Var

ExpVar returns a metrics.Set with metrics about the buffer.

  • counter_write_calls: Total number of calls to Filch.Write (excludes calls when file is closed).

  • counter_read_calls: Total number of calls to Filch.TryReadLine (excludes calls when file is closed or no bytes).

  • counter_rotate_calls: Total number of calls to rotate the log files (excludes calls when there is nothing to rotate to).

  • counter_call_errors: Total number of calls returning errors.

  • counter_write_bytes: Total number of bytes written (includes bytes filched from stderr).

  • counter_read_bytes: Total number of bytes read (includes bytes filched from stderr).

  • counter_filched_bytes: Total number of bytes filched from stderr.

  • counter_dropped_bytes: Total number of bytes dropped (includes bytes filched from stderr and lines too long to read).

  • gauge_stored_bytes: Current number of bytes stored on disk.

func (*Filch) TryReadLine

func (f *Filch) TryReadLine() (b []byte, err error)

TryReadline implements the logtail.Buffer interface.

func (*Filch) Write

func (f *Filch) Write(b []byte) (n int, err error)

Write implements the logtail.Buffer interface.

type Options

type Options struct {
	// ReplaceStderr specifies whether to filch [os.Stderr] such that
	// everything written there appears in the [Filch] buffer instead.
	// In order to write to stderr instead of writing to [Filch],
	// then use [Filch.OrigStderr].
	ReplaceStderr bool

	// MaxLineSize is the maximum line size that could be encountered,
	// including the trailing newline. This is enforced as a hard limit.
	// Writes larger than this will be rejected. Reads larger than this
	// will report an error and skip over the long line.
	// If zero, the [DefaultMaxLineSize] is used.
	MaxLineSize int

	// MaxFileSize specifies the maximum space on disk to use for logs.
	// This is not enforced as a hard limit, but rather a soft limit.
	// If zero, then [DefaultMaxFileSize] is used.
	MaxFileSize int
}

Jump to

Keyboard shortcuts

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