elapsed

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package elapsed provides elapsed time field configuration for clog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatFunc

func FormatFunc() func(time.Duration) string

FormatFunc returns the current custom format function, or nil if using default.

func GradientMax

func GradientMax() time.Duration

GradientMax returns the current gradient max duration. 0 means gradient is disabled.

func Minimum

func Minimum() time.Duration

Minimum returns the minimum duration threshold.

func Precision

func Precision() int

Precision returns the current decimal precision.

func Restore

func Restore(s Snapshot)

Restore resets the elapsed configuration to a previously saved Snapshot.

func Round

func Round() time.Duration

Round returns the current rounding duration.

func SetFormatFunc

func SetFormatFunc(fn func(time.Duration) string)

SetFormatFunc configures a custom format function for elapsed durations. When set, this function is used instead of the default formatter. Pass nil to restore the default.

func SetGradientMax

func SetGradientMax(d time.Duration)

SetGradientMax sets the max duration for elapsed gradient coloring. The gradient maps 0 → max onto the configured color stops. Set to 0 (the default) to disable gradient coloring.

func SetMinimum

func SetMinimum(d time.Duration)

SetMinimum sets the minimum duration below which elapsed fields are hidden. Defaults to time.Second. Set to 0 to show all values.

func SetPrecision

func SetPrecision(n int)

SetPrecision sets the decimal precision for elapsed time formatting. For example, 0 = "3s", 1 = "3.2s", 2 = "3.21s". Defaults to 0.

func SetRound

func SetRound(d time.Duration)

SetRound sets the rounding duration for elapsed time values. Defaults to time.Second. Set to 0 to disable rounding.

Types

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot captures the current state of all elapsed configuration. Use Restore to reset the state in test cleanup.

func Save

func Save() Snapshot

Save captures the current elapsed configuration so it can be restored later with Restore. Typical usage in tests:

snap := elapsed.Save()
t.Cleanup(func() { elapsed.Restore(snap) })

Jump to

Keyboard shortcuts

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