logging

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 12 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 builds the app's one logger.

The desktop bootstrap calls New once and hands the logger to everything that logs; no package logs through slog's default logger. Each record goes to two places:

  • stderr, as text, for whoever runs the binary from a terminal;
  • FileName in the data directory's logs folder, as JSON, for a bug report. The file is capped at MaxFileBytes: when the next record would pass the cap it is renamed to FileName.1 (and FileName.1 to FileName.2), so at most KeptFiles files and about 15 MB are kept. The files are readable only by the user.

A log file that cannot be opened, such as one in a folder the user cannot write, never stops the app: the logger writes to stderr alone and says why in its first record. With no data directory at all, it writes to stderr alone without a word.

Records at Info and above are kept. DebugFlag on the command line, or DebugEnv set to a true value, keeps Debug records too.

Index

Constants

View Source
const (
	// FileName is the log file's name in the logs folder.
	FileName = brand.Slug + ".log"

	// MaxFileBytes is the size a log file is rotated at.
	MaxFileBytes = 5 << 20

	// KeptFiles is how many log files are kept: FileName, FileName.1, and FileName.2.
	KeptFiles = 3

	// DebugFlag on the command line keeps Debug records.
	DebugFlag = "--debug"
)

Variables

This section is empty.

Functions

func DebugEnv

func DebugEnv() string

DebugEnv names the environment variable that keeps Debug records when it is set to a true value, such as 1.

func Level

func Level(args []string, getenv func(key string) string) slog.Level

Level returns the level a run logs at: slog.LevelDebug when args hold DebugFlag or getenv reports DebugEnv as true, else slog.LevelInfo.

func New

func New(paths appdata.Paths, level slog.Leveler) (*slog.Logger, io.Closer)

New returns the app's logger, which writes records at level and above as text to stderr and as JSON to FileName in paths.Logs, creating the folder if needed, and the Closer that closes the file. Without a logs folder the logger writes to stderr alone; when the file cannot be opened it does too, warning once why. The Closer then does nothing.

func Or

func Or(logger *slog.Logger) *slog.Logger

Or returns logger, or a logger that discards every record when logger is nil, so a service built without one logs nowhere rather than through slog's default logger.

Types

This section is empty.

Jump to

Keyboard shortcuts

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