fog

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: MIT Imports: 11 Imported by: 1

README

Overview

Welcome to Fog! There's a better name for this, I just haven't thought of it yet.

Fog is a slog-API-compatible logging package with a focus on user-facing, or "at the terminal", logging. This is to say: a primary focus is in-the-terminal readability. Fog makes use of ANSI colors to give your eyes clear markers to jump across when quickly scanning log output. It's also more customizable, allowing all log decorations to be toggled. It's also faster!

Who is this for?

Fog might work for you if:

  • You're implementing user-facing logging (command-line tooling, for example).
    • Fog allows tuning of all log decorations. Shipping to users: set flags to 0 and you get only clear log message output. Need to debug: set flags appropriately and you've got call stack, level and more.
  • Standard log mostly satisfies for your use-case, but man.. I still want log levels.
  • After deciding you want log levels, you try slog and find yourself writing slog.Error(... followed by an os.Exit(1) all over the place.
  • After the previous two items, you then say, "Well I'll just create this little package I can use to arrive at a sort of slog.Fatal.
  • After the previous three items, you decide to just wrap the slog.Logger into your own thing. But wait! Then your program counters for your call sites are all wrong!
  • After the previous four items: go get git.sr.ht/~illbjorn/fog and hakuna matata!

How does the performance of Fog compare to Slog?

In my own local benchmarks it's about ~2-3x faster than slog on average. But please bench it yourself! Checkout the repo and run task bench (install Task first if needed)

TODO

  • Need to unit test basically everything! But it is developed super iteratively and is holding up just fine in my own projects, fwiw.
  • Need to implement some structured logging handlers! Right now only the textHandler is available, but JSON is coming soon!

Documentation

Overview

GENERATED BY FLAGGER. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, values ...any) error

func Error

func Error(msg string, values ...any) error

func Fatal

func Fatal(msg string, values ...any)

func Info

func Info(msg string, values ...any) error

func IntoContext

func IntoContext(ctx context.Context, f *Fogger) context.Context

func SetDefault

func SetDefault(l *Fogger)

func SetFlags

func SetFlags(f FogFlags)

func Warn

func Warn(msg string, values ...any) error

Types

type FogFlags

type FogFlags uint8
const (
	FogWithCaller FogFlags = 1 << iota
	FogWithLevel
)

func (*FogFlags) FogWithCaller

func (self *FogFlags) FogWithCaller() bool

func (*FogFlags) FogWithLevel

func (self *FogFlags) FogWithLevel() bool

func (*FogFlags) SetFogWithCaller

func (self *FogFlags) SetFogWithCaller()

func (*FogFlags) SetFogWithLevel

func (self *FogFlags) SetFogWithLevel()

func (*FogFlags) UnsetFogWithCaller

func (self *FogFlags) UnsetFogWithCaller()

func (*FogFlags) UnsetFogWithLevel

func (self *FogFlags) UnsetFogWithLevel()

type Fogger

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

func Default

func Default() *Fogger

func FromContext

func FromContext(ctx context.Context) *Fogger

func Group

func Group(name string) *Fogger

func New

func New(h Handler) *Fogger

func With

func With(values ...any) *Fogger

func (*Fogger) Debug

func (self *Fogger) Debug(msg string, values ...any) error

func (*Fogger) Error

func (self *Fogger) Error(msg string, values ...any) error

func (*Fogger) Fatal

func (self *Fogger) Fatal(msg string, values ...any)

func (*Fogger) Group

func (self *Fogger) Group(name string) *Fogger

func (*Fogger) Info

func (self *Fogger) Info(msg string, values ...any) error

func (*Fogger) Panic

func (self *Fogger) Panic(msg string, values ...any)

func (*Fogger) SetFlags

func (self *Fogger) SetFlags(f FogFlags)

func (*Fogger) Warn

func (self *Fogger) Warn(msg string, values ...any) error

func (*Fogger) With

func (self *Fogger) With(values ...any) *Fogger

type Handler

type Handler interface {
	Enabled(l Level) bool
	Handle(pc []uintptr, f FogFlags, l Level, msg string, values ...[]byte) error
	WithAttrs(attrs ...any) Handler
	WithGroup(name string) Handler
	SetWriter(w io.Writer)
}

func TextHandler

func TextHandler(w io.Writer, level Level) Handler

type Level

type Level uint8
const (
	LevelDebug Level = 1 + iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

type Logger

type Logger interface {
	Debug(msg string, values ...any) error
	Info(msg string, values ...any) error
	Warn(msg string, values ...any) error
	Error(msg string, values ...any) error
}

Jump to

Keyboard shortcuts

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