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 ¶
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 ¶
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 ¶
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.
Types ¶
This section is empty.