Help us shape the future of Go! Take the 2026 Go Developer Survey

logging

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const LogBound = 100 * time.Millisecond

LogBound is what callers in this module pass: long enough for any handler that is working, short enough that one that is not cannot hold an exit.

Variables

This section is empty.

Functions

func LogWithin added in v0.30.0

func LogWithin(logger *slog.Logger, level slog.Level, timeout time.Duration, msg string, args ...any)

LogWithin logs at level under Within's bound. A nil logger logs nothing.

func WarnWithin added in v0.30.0

func WarnWithin(logger *slog.Logger, timeout time.Duration, msg string, args ...any)

WarnWithin is LogWithin at Warn, the level every caller so far wants.

func Within added in v0.30.0

func Within(timeout time.Duration, fn func())

Within runs fn on its own goroutine and waits at most timeout for it. A bounded wait that ends with a diagnostic must not be made unbounded by the diagnostic: a log handler blocked on a stopped terminal, or a message written to that same terminal, would otherwise hold the caller exactly where the bound was meant to release it. Fire-and-forget would lose the line at process exit; waiting under a bound loses it only when it was never going to be written. The goroutine is abandoned on timeout.

func WriteWithin added in v0.30.0

func WriteWithin(w io.Writer, timeout time.Duration, s string)

WriteWithin writes s to w under Within's bound: for a diagnostic to stderr, which may be the very terminal that stopped.

Types

type Logger

type Logger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

Logger wraps slog.Logger with cleanup capability and dynamic handlers

func Must

func Must(opts ...Option) *Logger

Must wraps NewWithOptions and panics on error

func New

func New(opts ...Option) (*Logger, error)

New creates a logger with options (for upterm client)

func (*Logger) Close

func (l *Logger) Close() error

Close cleans up resources

func (*Logger) With

func (l *Logger) With(args ...any) *Logger

With returns a new logger with additional attributes

func (*Logger) WithGroup

func (l *Logger) WithGroup(name string) *Logger

WithGroup returns a new logger with a group

type Option

type Option func(*config) error

Option configures a logger

func Console

func Console() Option

Console logs to stderr

func Debug

func Debug() Option

Debug sets debug level

func File

func File(path string) Option

File logs to a file (path is required)

func Level

func Level(level slog.Level) Option

Level sets the log level

func Sentry

func Sentry(dsn string) Option

Sentry enables Sentry error reporting

Jump to

Keyboard shortcuts

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