logger

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLoadingFailed = errors.New("loading failed")

ErrLoadingFailed is the sentinel cause passed to a Loading cancel function to indicate the operation failed (displays red X instead of green checkmark).

Functions

This section is empty.

Types

type FunLogger

type FunLogger struct {
	// The logs are `io.Copy`'d to this in a mutex. It's common to set this to a
	// file, or leave it default which is `os.Stderr`. You can also set this to
	// something more adventurous, such as logging to Kafka.
	Out io.Writer
	// Function to exit the application, defaults to `os.Exit()`
	ExitFunc exitFunc
	// Wg is a WaitGroup that can be used to wait for the loading animation to finish.
	Wg *sync.WaitGroup
	// IsCI is a boolean that is set to true if the logger is running in a CI environment.
	IsCI bool
	// contains filtered or unexported fields
}

FunFonts implements the Logger interface using emojis for messages.

func NewLogger

func NewLogger() *FunLogger

NewLogger creates a new instance of FunLogger.

func (*FunLogger) Check

func (l *FunLogger) Check(format string, a ...any)

Check prints an information message with a check emoji. Only prints if Verbosity >= VerbosityNormal.

func (*FunLogger) Debug added in v0.3.0

func (l *FunLogger) Debug(format string, a ...any)

Debug prints a debug message. Only prints if Verbosity >= VerbosityVerbose.

func (*FunLogger) Error

func (l *FunLogger) Error(err error)

Error prints an error message with an X emoji. Always prints regardless of verbosity level.

func (*FunLogger) Exit

func (l *FunLogger) Exit(code int)

func (*FunLogger) Info

func (l *FunLogger) Info(format string, a ...any)

Info prints an information message with no emoji. Only prints if Verbosity >= VerbosityNormal.

func (*FunLogger) Loading

func (l *FunLogger) Loading(format string, a ...any) context.CancelCauseFunc

Loading starts a loading animation in a background goroutine and returns a CancelCauseFunc. The caller MUST invoke the returned function to stop:

  • cancel(nil) → success (green checkmark)
  • cancel(logger.ErrLoadingFailed) → failure (red X)

Each invocation is independent — multiple concurrent Loading calls do not interfere with each other.

func (*FunLogger) SetVerbosity added in v0.3.0

func (l *FunLogger) SetVerbosity(v Verbosity)

SetVerbosity sets the verbosity level for the logger.

func (*FunLogger) Trace added in v0.3.0

func (l *FunLogger) Trace(format string, a ...any)

Trace prints a trace message. Only prints if Verbosity >= VerbosityDebug.

func (*FunLogger) Warning

func (l *FunLogger) Warning(format string, a ...any)

Warning prints a warning message with a warning emoji. Always prints regardless of verbosity level (like Error).

type Logger

type Logger interface {
	Info(format string, a ...any)
	Check(format string, a ...any)
	Warning(format string, a ...any)
	Error(err error)
	Loading(format string, a ...any) context.CancelCauseFunc
	Debug(format string, a ...any)
	Trace(format string, a ...any)
	SetVerbosity(v Verbosity)
}

Printer interface defines methods for logging info, warning, and error messages.

type Verbosity added in v0.3.0

type Verbosity int

Verbosity represents the logging verbosity level.

const (
	// VerbosityQuiet suppresses all output except errors.
	VerbosityQuiet Verbosity = iota
	// VerbosityNormal is the default verbosity level.
	VerbosityNormal
	// VerbosityVerbose enables debug output.
	VerbosityVerbose
	// VerbosityDebug enables trace output.
	VerbosityDebug
)

Jump to

Keyboard shortcuts

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