logging

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package logging builds the agent's structured logger over a size- and age-bounded file on the state mount, teed to stderr.

Two guarantees this package exists to keep, both PRD requirements:

  • Log lines written before a crash are readable after a restart. That is why the sink is a file on the bind-mounted state directory and not only stderr.
  • The agent must never be the reason a small VPS runs out of disk. That is why the on-disk total is bounded by whichever of size or age is hit first.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rotator

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

Rotator forces a log rotation on a fixed interval.

This is NOT redundant with lumberjack's own behaviour, and deleting it would silently break age-based retention. lumberjack rotates on SIZE only, and it applies MaxAge only at the moment a rotation happens. A quiet agent never fills a file, so it never rotates, so it never prunes — its agent.log would keep entries from months ago while sitting comfortably under the size cap. The ticker is what makes DEVMON_LOG_MAX_AGE_DAYS mean anything.

func NewRotator

func NewRotator(lj *lumberjack.Logger, interval time.Duration, log *slog.Logger) *Rotator

NewRotator returns a Rotator that rotates lj every interval.

func (*Rotator) Run

func (r *Rotator) Run(ctx context.Context) error

Run rotates on each tick until ctx is cancelled, returning ctx.Err().

A failed rotation is logged and the loop continues: losing retention is bad, but taking the agent down over it is worse.

type Sink

type Sink struct {
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Sink owns the agent's logger and the file it writes to. It must be closed on shutdown so buffered bytes reach disk before the process exits.

func NewSink

func NewSink(cfg config.Config) (*Sink, error)

NewSink creates the logs directory, opens the rotated log file, and returns a slog logger writing to both that file and stderr.

The stderr tee is not redundant: `docker logs devmon-agent` is the operator's first diagnostic, and it only sees the process's standard streams.

func (*Sink) Close

func (s *Sink) Close() error

Close flushes and closes the log file.

func (*Sink) Run

func (s *Sink) Run(ctx context.Context) error

Run drives periodic rotation until ctx is cancelled.

Jump to

Keyboard shortcuts

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