file

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 8 Imported by: ? 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 file is a simple log-to-disk plugin with size-based rotation. Useful for operators who want a persistent record of logs separate from Docker's own log files (which rotate on container restart and aren't easy to grep).

Design: small, sync, lossy on crash. We don't reach for an external rotator like lumberjack to keep the dep tree light; rotation is a bounded slot system: when the active file exceeds MaxBytes, it's renamed to <path>.1 and a new active file opens. MaxFiles controls how many .1, .2, … to keep before deleting.

This plugin writes JSON lines (one record per line), the same format as the stdout handler. So you can `cat /logs/pulse.log | jq` and it Just Works.

Operator config:

BEACON_LOG_FILE_PATH      — file path (e.g. /config/logs/pulse.log)
BEACON_LOG_FILE_MAX_BYTES — rotate at this size (default 10MB)
BEACON_LOG_FILE_MAX_FILES — keep this many rotated files (default 5)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path     string
	MaxBytes int64 // default 10 MB
	MaxFiles int   // default 5
}

Config controls the file plugin.

type Plugin

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

Plugin implements log.Plugin.

func New

func New(cfg Config) (*Plugin, error)

New opens the file (creating parent dirs if needed) and returns a started plugin. Returns an error if the path is empty or the parent dir can't be created.

func (*Plugin) Close

func (p *Plugin) Close(_ context.Context) error

Close flushes pending writes and closes the file. Idempotent.

func (*Plugin) Handler

func (p *Plugin) Handler() slog.Handler

Handler returns the slog.Handler that writes to the file.

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns "file".

Jump to

Keyboard shortcuts

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