logger.go

Functions

Functions

func Enabled

func (nopHandler) Enabled(context.Context, slog.Level) bool	{ return false }

func Handle

func (nopHandler) Handle(context.Context, slog.Record) error	{ return nil }

func Logger

Logger returns the current logger used by ui.

Sub-packages call this to share the same logger configuration

without introducing import cycles.

 

Logger is safe for concurrent use.

func Logger() *slog.Logger {
	return loggerPtr.Load()
}

func SetLogger

SetLogger configures the logger for the ui toolkit.

By default, ui produces no log output. Call SetLogger to enable logging.

 

SetLogger is safe for concurrent use: it stores the new logger atomically.

Pass nil to disable logging (restore default silent behavior).

 

Log levels used by ui:

- [slog.LevelDebug]: internal diagnostics (layout calculations, focus changes)

- [slog.LevelInfo]: important lifecycle events (plugin loaded, theme applied)

- [slog.LevelWarn]: non-fatal issues (widget paint errors, constraint violations)

 

Example:

 

// Enable info-level logging to stderr:

ui.SetLogger(slog.Default())

 

// Enable debug-level logging for full diagnostics:

ui.SetLogger(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{

Level: slog.LevelDebug,

})))

func SetLogger(l *slog.Logger) {
	if l == nil {
		l = slog.New(nopHandler{})
	}
	loggerPtr.Store(l)
}

func WithAttrs

func (nopHandler) WithAttrs([]slog.Attr) slog.Handler	{ return nopHandler{} }

func WithGroup

func (nopHandler) WithGroup(string) slog.Handler	{ return nopHandler{} }