testlog

package
v0.0.0-...-8c930d8 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testlog keeps the framework's logs of a test process out of the test output and out of the package source tree, where log files changing with every run would make go's test cache rerun every test that reads or lists the tree. testutil.Run points the logs away through ToTempDir, and so does every test package that bootstraps the framework or initializes the loggers on its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToTempDir

func ToTempDir() (dir string, release func() error, err error)

ToTempDir points every log stream at a new scratch directory in file mode, and returns the directory with the function that removes it. It exports the settings through the environment, where config.Init reads them, and writes them to config.App.Logger as well, for a process that initializes the loggers without config.Init; either way it runs before the loggers come up.

File mode alone does not keep the logs out of the test output: the global stream still writes to stdout when it names no file, and the console mirror copies it there when it names one. So the global stream gets a file of its own and the mirror is turned off.

The files are not evidence a test can read back: the directory goes away at release, and every file sink buffers its entries (see the buffered writer in the logger package), so a test process that ends within the flush interval leaves most of them empty. A test that needs to assert on log output instead swaps the package logger it cares about for a scratch file logger under its own t.TempDir and flushes that one before reading — see withCronjobLoggerConfig and readLogEntry in the cronjob tests.

The release stops the log writers before it removes the directory. They hold entries back for up to a second, and a file writer opens its file on its first write, creating the directory when it is missing, so a write arriving after the removal would recreate the directory and leave it behind.

Types

This section is empty.

Jump to

Keyboard shortcuts

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