logtest

package
v0.37.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package logtest provides small helpers for tests that assert on the JSON-encoded log file written by the file logging setup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFileJSONLogger

func NewFileJSONLogger(t *testing.T) (logr.Logger, string)

NewFileJSONLogger returns a logger that writes JSON encoded records to a log file, together with the path of that file. Read the most recent record back with ReadJSONRecord.

loft-sh/log/logr registers its file sink once per process and rejects a second registration at a different path, so the logger and its file are created on the first call and reused by every later call in this process (other tests in the same package, or the same test under -count=2).

func ReadJSONRecord

func ReadJSONRecord(t *testing.T, path string) map[string]any

ReadJSONRecord reads the log file at path and decodes its last line as a single JSON log record. The file is shared across every NewFileJSONLogger caller in this process, so the last line is the most recently written record rather than necessarily the only one.

Types

This section is empty.

Jump to

Keyboard shortcuts

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