sqlogger

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package sqlogger provides a custom slog.Handler that logs to a SQLite database and standard output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Err

func Err(err error) slog.Attr

func FiberRequestLogger

func FiberRequestLogger(c *fiber.Ctx) error

FiberRequestLogger logs HTTP requests on entry and exit

Types

type ByteRenderer

type ByteRenderer struct {
	bytes.Buffer
}

func (*ByteRenderer) CloneBytes

func (r *ByteRenderer) CloneBytes() []byte

CloneBytes returns a copy of the buffer contents, so the returned copy is owned by the caller

func (*ByteRenderer) Render

func (r *ByteRenderer) Render(inputs ...any)

func (*ByteRenderer) Renderln

func (r *ByteRenderer) Renderln(inputs ...any)

type LogRecord

type LogRecord struct {
	Seconds int64
	Nanos   int32
	Level   string
	Content string
}

type Options

type Options struct {
	// Level reports the minimum level to log.
	// Levels with lower levels are discarded.
	// If nil, the Handler uses [slog.LevelInfo].
	Level slog.Leveler

	NoColor bool

	// LogDir specifies the directory where log files will be stored.
	// If empty, the current working directory is used.
	LogDir string
}

type SQLogHandler

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

func NewSQLogHandler

func NewSQLogHandler(opts *Options) (*SQLogHandler, error)

func (*SQLogHandler) Close

func (h *SQLogHandler) Close()

func (*SQLogHandler) Enabled

func (h *SQLogHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*SQLogHandler) Handle

func (h *SQLogHandler) Handle(c context.Context, r slog.Record) error

func (*SQLogHandler) Level

func (h *SQLogHandler) Level() *slog.LevelVar

func (*SQLogHandler) Name

func (h *SQLogHandler) Name() string

func (*SQLogHandler) Retrieve

func (h *SQLogHandler) Retrieve(numEntries int) ([]LogRecord, error)

Retrieve returns up to numEntries most recent LogRecord entries from the log handler. If there are fewer than numEntries available, all available entries are returned. Returns a slice of LogRecord and an error if retrieval fails.

func (*SQLogHandler) WithAttrs

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

func (*SQLogHandler) WithGroup

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

type SQLogHandlerInterface

type SQLogHandlerInterface interface {
	slog.Handler
	Retrieve(numEntries int) ([]LogRecord, error)
}

type StringRenderer

type StringRenderer struct {
	strings.Builder
}

func (*StringRenderer) Render

func (r *StringRenderer) Render(inputs ...any)

func (*StringRenderer) RenderWithSeparator

func (r *StringRenderer) RenderWithSeparator(separator string, inputs ...any)

func (*StringRenderer) Renderln

func (r *StringRenderer) Renderln(inputs ...any)

Jump to

Keyboard shortcuts

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