slogger

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const TraceIDKey = "trace_id"

Variables

View Source
var Strings = map[slog.Level]string{
	slog.LevelDebug: "•",
	slog.LevelInfo:  "•",
	slog.LevelWarn:  "•",
	slog.LevelError: "⨯",
}

Functions

func InitCLIDefault

func InitCLIDefault()

InitCLIDefault

func InitDefault

func InitDefault()

InitDefault make default

func NewHandler

func NewHandler(options *options) slog.Handler

func NewHandlerOptions

func NewHandlerOptions(level slog.Leveler, opt *Options) slog.HandlerOptions

func NewLogger

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

NewLogger create a new *slog.Logger with tracing handler wrapper

Types

type CLIHandler

type CLIHandler struct {
	slog.Handler
	// contains filtered or unexported fields
}

func NewCLIHandler

func NewCLIHandler(
	out io.Writer,
	opts *CLIHandlerOptions,
) *CLIHandler

func (*CLIHandler) Enabled

func (h *CLIHandler) Enabled(ctx context.Context, l slog.Level) bool

func (*CLIHandler) Handle

func (h *CLIHandler) Handle(_ context.Context, r slog.Record) error

func (*CLIHandler) WithAttrs

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

func (*CLIHandler) WithGroup

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

type CLIHandlerOptions

type CLIHandlerOptions struct {
	DisableColor bool
	slog.HandlerOptions
}

type Option

type Option func(o *options)

Option is an application option.

func WithDisableSource

func WithDisableSource() Option

func WithDisableTime

func WithDisableTime() Option

func WithFormat

func WithFormat(format string) Option

func WithFullSource

func WithFullSource() Option

func WithLevel

func WithLevel(level string) Option

func WithOrganization added in v1.3.1

func WithOrganization(name string) Option

func WithOutput

func WithOutput(output string) Option

func WithTracing

func WithTracing() Option

func WithWriter

func WithWriter(w io.Writer) Option

type Options

type Options struct {
	DisableSource bool
	FullSource    bool
	DisableTime   bool
	DisableColor  bool // for cli

	// for format
	Name         string
	Organization string
	Context      string
}

Options

type TracingHandler

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

func NewTracingHandler

func NewTracingHandler(h slog.Handler) *TracingHandler

func (*TracingHandler) Enabled

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

Enabled implements Handler.Enabled by reporting whether level is at least as large as h's level.

func (*TracingHandler) Handle

func (h *TracingHandler) Handle(ctx context.Context, r slog.Record) error

Handle implements Handler.Handle.

func (*TracingHandler) Handler

func (h *TracingHandler) Handler() slog.Handler

Handler returns the Handler wrapped by handler.

func (*TracingHandler) WithAttrs

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

WithAttrs implements Handler.WithAttrs.

func (*TracingHandler) WithGroup

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

WithGroup implements Handler.WithGroup.

Jump to

Keyboard shortcuts

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