devlog

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package devlog wires slog.Default() based on the build channel and the resolved log level.

In dev: writes to <CacheDir>/debug.log at DEBUG or higher (depending on Options.Level).

In release: writes to <CacheDir>/ccpulse.log at INFO or higher (depending on Options.Level). Set Options.Level to LevelOff to disable logging entirely; no file is opened and slog.Default() is set to a discard handler.

External rotation: this package does not rotate logs. Users who want bounded log size should rotate the log file externally (e.g. logrotate). Because the file is held open for append, external mv/rm will not take effect for the running ccpulse — restart to pick up the new inode.

Init is best-effort: on any failure (mkdir or open) it sets slog.Default to the discard handler before returning the error, so callers can ignore the error and the binary keeps running quietly.

Index

Constants

View Source
const LevelOff slog.Level = slog.LevelError + 4

LevelOff is a sentinel slog.Level above every real level. Init treats it specially: no file is opened, slog.Default() is set to a discard handler. Mapped to LevelError + 4 so future custom levels between Error and Off remain expressible without renumbering.

Variables

This section is empty.

Functions

func Init

func Init(opts Options) (io.Closer, error)

Init configures slog.Default() per opts. Returns the opened log file (caller may close on shutdown) when a file is opened, or nil when no file is needed (Level == LevelOff).

Init is best-effort: on any failure path slog.Default is set to the discard handler so the binary keeps running quietly even if logging could not be set up.

func ParseLevel

func ParseLevel(s string) (slog.Level, error)

ParseLevel converts a flag value to a slog.Level. The accepted set is off | error | warn | info | debug (case-insensitive). Unknown values return an error so cobra reports the flag failure cleanly.

Types

type Options

type Options struct {
	IsDev    bool
	CacheDir string
	Level    slog.Level
}

Options configures Init. Construct one per process. CacheDir must be the resolved (tilde-expanded, env-overridden) cache directory; Init does not re-expand. Level is the resolved level (see ParseLevel).

Jump to

Keyboard shortcuts

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