logui

package
v0.0.0-...-bedf5c0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MPL-2.0 Imports: 24 Imported by: 3

Documentation

Overview

Example
app2 := app.New(context.Background(), "com.github.diamondburned.gotkit.components.logui", "logui")
app2.ConnectActivate(func() {
	adw.Init()

	slog.Debug("example debug message", "key", "value")
	slog.Info("example info message", "key", "value")
	slog.Warn("example warn message", "key", "value")
	slog.Error("example error message", "key", "value")

	win := app2.NewWindow()
	win.SetTitle("Log Viewer")
	win.SetChild(gtk.NewLabel("Log viewer demo"))
	win.Show()

	ctx := app.WithWindow(app2.Context(), win)
	logui.ShowDefaultViewer(ctx)
})
app2.Run(nil)
Output:

Index

Examples

Constants

View Source
const DefaultMaxEntries = 1000

DefaultMaxEntries is the default maximum number of log entries.

Variables

View Source
var LogListModelType = gioutil.NewListModelType[slog.Record]()

Functions

func MultiHandler

func MultiHandler(handlers ...slog.Handler) slog.Handler

MultiHandler creates a slog.Handler that duplicates its writes to all the provided handlers, similar to the Unix tee(1) command.

Each write is written to each listed writer, one at a time. If a listed writer returns an error, that overall write operation stops and returns the error; it does not continue down the list.

func RecordsToString

func RecordsToString(iter func(yield func(slog.Record) bool)) string

RecordsToString returns a string representation of the given log records.

func SetDefaultLevel

func SetDefaultLevel(level slog.Leveler)

SetDefaultLevel sets the default level for the default log handler.

func SetLogger

func SetLogger(logger *slog.Logger)

SetLogger sets the default slog.Logger to the given logger. The logger is automatically wrapped with the default log handler. Call this function only once the main loop is running.

func ShowDefaultViewer

func ShowDefaultViewer(ctx context.Context)

ShowDefaultViewer calls NewDefaultViewer then Show.

func WrapLogger

func WrapLogger(logger *slog.Logger) *slog.Logger

WrapLogger wraps the given logger with the default logui's log handler. Call this function only once the main loop is running.

Types

type LogHandler

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

LogHandler is a slog.Handler that stores logs in a list model. To obtain the list model, use the [ListModel] method.

func DefaultLogHandler

func DefaultLogHandler() *LogHandler

DefaultLogHandler returns the default log handler. Debug logs are enabled by default.

func NewDebugLogHandler

func NewDebugLogHandler(maxEntries int) *LogHandler

NewDebugLogHandler creates a new LogHandler that logs all levels, including debug.

func NewLogHandler

func NewLogHandler(maxEntries int, opts *slog.HandlerOptions) *LogHandler

NewLogHandler creates a new LogHandler with the given options. If maxEntries is 0, then the list model will have no limit.

func (*LogHandler) Enabled

func (h *LogHandler) Enabled(_ context.Context, level slog.Level) bool

func (*LogHandler) Handle

func (h *LogHandler) Handle(_ context.Context, record slog.Record) error

func (*LogHandler) Level

func (h *LogHandler) Level() slog.Leveler

Level returns the current level of the handler. This method is thread-safe.

func (*LogHandler) ListModel

func (h *LogHandler) ListModel() *LogListModel

ListModel returns the list model that contains the logs. Only the main thread should access this list model.

func (*LogHandler) SetLevel

func (h *LogHandler) SetLevel(level slog.Leveler)

SetLevel sets the level of the handler. This method is thread-safe.

func (*LogHandler) WithAttrs

func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*LogHandler) WithGroup

func (h *LogHandler) WithGroup(name string) slog.Handler

type LogListModel

type LogListModel = gioutil.ListModel[slog.Record]

type Viewer

type Viewer struct {
	*adw.ApplicationWindow
	View  *gtk.ColumnView
	Model *LogListModel
	// contains filtered or unexported fields
}

Viewer is a TextView dialog that views a particular log buffer in real time.

func NewDefaultViewer

func NewDefaultViewer(ctx context.Context) *Viewer

NewDefaultViewer creates a new viewer on the default buffer.

func NewViewer

func NewViewer(ctx context.Context, model *LogListModel) *Viewer

NewViewer creates a new log viewer dialog.

Jump to

Keyboard shortcuts

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