minimal

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MPL-2.0 Imports: 8 Imported by: 1

README

minimal is a small CLI-focused logger with distinct status markers, automatic terminal color detection and separate standard and error output streams.

log := minimal.New()

_ = log.Infof("building %s\n", target)
_ = log.Stepln("compiling packages")
_ = log.Subln("generated configuration")
_ = log.Successln("build complete")
_ = log.Warnln("cache unavailable")
_ = log.Errorln("build failed")

Info, Step, Success, Warn and Sub write to stdout by default. Error writes to stderr. The f methods do not add a newline; use a newline in the format or use the corresponding ln method.

Configuration

log := minimal.New(
	minimal.WithTarget(output),
	minimal.WithErrorTarget(errorOutput),
	minimal.WithColor(minimal.ColorAuto),
)

ColorAuto emits color only when the selected stream is a color-capable terminal. ColorAlways forces ANSI output, while ColorNever strips ANSI sequences. minimal.ToStdErr() routes every message to stderr.

Every write method returns the underlying writer error. MustFail and MustExit are convenience methods for terminal error paths where no error can be returned to the caller.

Documentation

Index

Constants

View Source
const (
	AnsiSub     = ansi.AnsiHiBlack
	AnsiStep    = ansi.AnsiHiBlue
	AnsiInfo    = ansi.AnsiCyan
	AnsiSuccess = ansi.AnsiGreen
	AnsiWarn    = ansi.AnsiYellow
	AnsiError   = ansi.AnsiRed
	AnsiReset   = ansi.AnsiReset
)

Variables

This section is empty.

Functions

func ToStdErr

func ToStdErr() option

ToStdErr sets both output writers to standard error.

func WithColor

func WithColor(mode ColorMode) option

WithColor controls when the logger emits ANSI color sequences.

func WithErrorTarget

func WithErrorTarget(out io.Writer) option

WithErrorTarget sets the error output writer used by the logger.

func WithTarget

func WithTarget(out io.Writer) option

WithTarget sets the standard output writer used by the logger.

Types

type ColorMode

type ColorMode uint8
const (
	ColorAuto ColorMode = iota
	ColorAlways
	ColorNever
)

type Minimal

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

func New

func New(opts ...option) *Minimal

New creates a Minimal logger configured by the provided options.

func (*Minimal) Error

func (m *Minimal) Error(a ...any) error

Error writes its operands to the error target as an error message.

func (*Minimal) Errorf

func (m *Minimal) Errorf(format string, a ...any) error

Errorf formats according to a format specifier and writes to the error target as an error message.

func (*Minimal) Errorln

func (m *Minimal) Errorln(a ...any) error

Errorln writes its operands to the error target as an error message with a trailing newline.

func (*Minimal) Info

func (m *Minimal) Info(a ...any) error

Info writes its operands to the standard target as an info message.

func (*Minimal) Infof

func (m *Minimal) Infof(format string, a ...any) error

Infof formats according to a format specifier and writes to the standard target as an info message.

func (*Minimal) Infoln

func (m *Minimal) Infoln(a ...any) error

Infoln writes its operands to the standard target as an info message with a trailing newline.

func (*Minimal) MustExit

func (m *Minimal) MustExit(err error)

MustExit logs and exits with code 1 if err is not nil.

func (*Minimal) MustFail

func (m *Minimal) MustFail(err error)

MustFail logs and panics if err is not nil.

func (*Minimal) Step added in v1.6.2

func (m *Minimal) Step(a ...any) error

Step writes its operands to the standard target as a step message.

func (*Minimal) Stepf added in v1.6.2

func (m *Minimal) Stepf(format string, a ...any) error

Stepf formats according to a format specifier and writes to the standard target as a step message.

func (*Minimal) Stepln added in v1.6.2

func (m *Minimal) Stepln(a ...any) error

Stepln writes its operands to the standard target as a step message with a trailing newline.

func (*Minimal) Sub

func (m *Minimal) Sub(a ...any) error

Sub writes its operands to the standard target as a sub-message.

func (*Minimal) Subf

func (m *Minimal) Subf(format string, a ...any) error

Subf formats according to a format specifier and writes to the standard target as a sub-message.

func (*Minimal) Subln

func (m *Minimal) Subln(a ...any) error

Subln writes its operands to the standard target as a sub-message with a trailing newline.

func (*Minimal) Success

func (m *Minimal) Success(a ...any) error

Success writes its operands to the standard target as a success message.

func (*Minimal) Successf

func (m *Minimal) Successf(format string, a ...any) error

Successf formats according to a format specifier and writes to the standard target as a success message.

func (*Minimal) Successln

func (m *Minimal) Successln(a ...any) error

Successln writes its operands to the standard target as a success message with a trailing newline.

func (*Minimal) Warn

func (m *Minimal) Warn(a ...any) error

Warn writes its operands to the standard target as a warning.

func (*Minimal) Warnf

func (m *Minimal) Warnf(format string, a ...any) error

Warnf formats according to a format specifier and writes to the standard target as a warning.

func (*Minimal) Warnln

func (m *Minimal) Warnln(a ...any) error

Warnln writes its operands to the standard target as a warning with a trailing newline.

func (*Minimal) Write

func (m *Minimal) Write(color string, a ...any) error

Write writes its operands to the standard target using the provided ANSI color code.

func (*Minimal) Writef

func (m *Minimal) Writef(color, format string, a ...any) error

Writef formats according to a format specifier and writes to the standard target using the provided ANSI color code.

func (*Minimal) Writeln

func (m *Minimal) Writeln(color string, a ...any) error

Writeln writes its operands to the standard target using the provided ANSI color code with a trailing newline.

Jump to

Keyboard shortcuts

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