logger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatJson    = "json"
	FormatText    = "text"
	FormatPretty  = "pretty"
	FormatDiscard = "discard"

	LevelDebug = "debug"
	LevelInfo  = "info"
	LevelWarn  = "warn"
	LevelError = "error"
)

Variables

This section is empty.

Functions

func New

func New(opts ...Option) *slog.Logger

func NewPrettyHandler

func NewPrettyHandler(w io.Writer, opts *Options) slog.Handler

Types

type Buffer

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

func (*Buffer) AppendBool

func (b *Buffer) AppendBool(v bool)

func (*Buffer) AppendByte

func (b *Buffer) AppendByte(p byte)

func (*Buffer) AppendBytes

func (b *Buffer) AppendBytes(p []byte)

func (*Buffer) AppendFloat

func (b *Buffer) AppendFloat(f float64, bitSize int)

func (*Buffer) AppendFloat32

func (b *Buffer) AppendFloat32(f float32)

func (*Buffer) AppendFloat64

func (b *Buffer) AppendFloat64(f float64)

func (*Buffer) AppendInt

func (b *Buffer) AppendInt(i int64)

func (*Buffer) AppendQuote

func (b *Buffer) AppendQuote(s string)

func (*Buffer) AppendString

func (b *Buffer) AppendString(s string)

func (*Buffer) AppendTimeFormat

func (b *Buffer) AppendTimeFormat(t time.Time, layout string)

func (*Buffer) AppendUint

func (b *Buffer) AppendUint(i uint64)

func (*Buffer) Cap

func (b *Buffer) Cap() int

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) Replace

func (b *Buffer) Replace(i int, p byte)

func (*Buffer) Reset

func (b *Buffer) Reset()

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (int, error)

func (*Buffer) WriteTo

func (b *Buffer) WriteTo(writer io.Writer) (int64, error)

type LevelFormatter

type LevelFormatter func(buf *Buffer, l slog.Level)

func DefaultLevelFormatter

func DefaultLevelFormatter(color bool) LevelFormatter

type Option

type Option func(c *config)

func WithFormat

func WithFormat(format string) Option

func WithLevel

func WithLevel(level string) Option

func WithOptions

func WithOptions(opts *Options) Option

func WithWriter

func WithWriter(w io.Writer) Option

type Options

type Options struct {
	// Level is the minimum [slog.Level] that will be logged.
	// Records with lower levels will be discarded.
	Level slog.Leveler

	// ReplaceAttr is used to rewrite each non-group [slog.Attr] before it is
	// logged. See https://pkg.go.dev/log/slog#HandlerOptions for details.
	ReplaceAttr ReplaceAttrFunc

	// AddSource enables computing the source code position of the log
	// statement and adds [slog.SourceKey] attributes to the output.
	AddSource bool

	// DisableColor disables the use of ANSI colour codes in messages.
	DisableColor bool

	// TimeFormatter is the [time.Time] formatter used to format log timestamps.
	TimeFormatter TimeFormatter

	// LevelFormatter is the [slog.Level] formatter used to format log levels.
	LevelFormatter LevelFormatter

	// SourceFormatter is the [slog.Source] formatter used to format log sources.
	SourceFormatter SourceFormatter
}

func (*Options) ToSlogHandleOptions

func (o *Options) ToSlogHandleOptions() *slog.HandlerOptions

type PrettyHandler

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

func (*PrettyHandler) Enabled

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

func (*PrettyHandler) Handle

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

func (*PrettyHandler) WithAttrs

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

func (*PrettyHandler) WithGroup

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

type ReplaceAttrFunc

type ReplaceAttrFunc func(groups []string, attr slog.Attr) slog.Attr

type SourceFormatter

type SourceFormatter func(buf *Buffer, src *slog.Source)

func DefaultSourceFormatter

func DefaultSourceFormatter(color bool) SourceFormatter

type TimeFormatter

type TimeFormatter func(buf *Buffer, t time.Time)

func DefaultTimeFormatter

func DefaultTimeFormatter(layout string) TimeFormatter

Jump to

Keyboard shortcuts

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