logging

package
v2.2.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: 11 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 logging makes the logger gist writes its log file with: JSON lines through log/slog, to a file under the state directory, never to the terminal the TUI draws on.

The logger is made once, in the app package, and passed down. A log line never holds a token, or the content, description or comments of a gist: a gist is named by its ID and a file by its name.

Index

Constants

View Source
const (
	KeyRun           = "run"
	KeyVersion       = "version"
	KeyDurationMS    = "duration_ms"
	KeyGHRequestID   = "gh_request_id"
	KeyRateRemaining = "rate_remaining"
)

Attribute keys every package uses, so a log line can be searched by them.

View Source
const (
	DefaultMaxSize = 10 << 20
	DefaultKeep    = 3
)

Rotation defaults: the file is moved aside when it is over MaxSize at startup, and Keep old files are kept.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath is where the log file goes: log/gist.log in the state directory.

func Discard

func Discard() *slog.Logger

Discard is a logger that writes nothing, for code run without one.

func Follow

func Follow(ctx context.Context, w io.Writer, path string) error

Follow writes each line added to the log file at path to w, until ctx is done. It follows the file through a rotation, and waits for a file that does not exist yet.

func New

func New(w io.Writer, level slog.Leveler) *slog.Logger

New returns a logger writing JSON lines to w at level and above. Tests pass a buffer.

func NewID

func NewID() string

NewID returns a short random ID, for a run.

func Open

func Open(o Options) (*slog.Logger, io.Closer, error)

Open rotates the log file if it has grown past MaxSize, opens it for appending, and returns a logger writing JSON lines to it. Closing the returned closer closes the file.

func ParseLevel

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

ParseLevel reads a level as written in the environment: debug, info, warn or error.

Types

type Options

type Options struct {
	// Path is the log file; DefaultPath when empty.
	Path string
	// Level is the lowest level written.
	Level slog.Leveler
	// MaxSize and Keep control rotation at startup; the defaults when zero.
	MaxSize int64
	Keep    int
}

Options say where and what to log.

Jump to

Keyboard shortcuts

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