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 ¶
- Constants
- Variables
- func MultiHandler(handlers ...slog.Handler) slog.Handler
- func RecordsToString(iter func(yield func(slog.Record) bool)) string
- func SetDefaultLevel(level slog.Leveler)
- func SetLogger(logger *slog.Logger)
- func ShowDefaultViewer(ctx context.Context)
- func WrapLogger(logger *slog.Logger) *slog.Logger
- type LogHandler
- func (h *LogHandler) Enabled(_ context.Context, level slog.Level) bool
- func (h *LogHandler) Handle(_ context.Context, record slog.Record) error
- func (h *LogHandler) Level() slog.Leveler
- func (h *LogHandler) ListModel() *LogListModel
- func (h *LogHandler) SetLevel(level slog.Leveler)
- func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *LogHandler) WithGroup(name string) slog.Handler
- type LogListModel
- type Viewer
Examples ¶
Constants ¶
const DefaultMaxEntries = 1000
DefaultMaxEntries is the default maximum number of log entries.
Variables ¶
var LogListModelType = gioutil.NewListModelType[slog.Record]()
Functions ¶
func MultiHandler ¶
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 ¶
RecordsToString returns a string representation of the given log records.
func SetDefaultLevel ¶
SetDefaultLevel sets the default level for the default log handler.
func SetLogger ¶
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 ¶
ShowDefaultViewer calls NewDefaultViewer then Show.
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) 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.
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 ¶
NewDefaultViewer creates a new viewer on the default buffer.