logcap

package
v0.148.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 7 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 logcap keeps the daemon's log file from growing without bound.

The daemon logs to stderr, and whoever started it decides where that goes: `caprock up` points it at <data_dir>/caprock.log, launchd and systemd at <data_dir>/service.log, a terminal at the terminal. Nothing ever trimmed either file. On the owner's machine caprock.log reached 4.6GB — 1.1M copies of one warning — before anyone looked.

When stderr is a regular file past Limit, it is renamed to <name>.1 (replacing the previous one) and a fresh file is opened and put in place of stdout and stderr, so the rest of the process keeps writing without knowing. Renaming rather than truncating does not depend on how the file was opened: launchd's descriptor may or may not append, and truncating a file someone writes to without O_APPEND leaves a hole the size of everything before.

Index

Constants

View Source
const (
	// Limit is the size at which the log is rotated. One previous file is
	// kept, so the most a data dir ever holds is about twice this.
	Limit = 64 << 20
	// Keep is how much of the end of an old log trimIdle leaves.
	Keep = 8 << 20
	// Every is how often the size is checked.
	Every = 10 * time.Minute
)

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, log *slog.Logger)

Run checks now and then every Every until ctx ends. A no-op when stderr is not a regular file (a terminal, a pipe) and on platforms that cannot swap a process's standard descriptors.

func Watch

func Watch(p ...string)

Watch names the files the daemon may be logging to. Only a file named here is ever renamed, so an unexpected stderr — another program's log, a file the user redirected to — is left alone.

Types

This section is empty.

Jump to

Keyboard shortcuts

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