tidbits

package
v0.0.0-...-532ff07 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const StackAttrName = "stack"
View Source
const TIDBITS_ENV_PREFIX = "TIDBITS_LOG_"

Variables

View Source
var BlackBackground = "\033[40m"
View Source
var BlueBackground = "\033[44m"
View Source
var ColorBlue = "\033[34m"
View Source
var ColorCyan = "\033[36m"
View Source
var ColorGray = "\033[37m"
View Source
var ColorGreen = "\033[32m"
View Source
var ColorRed = "\033[31m"
View Source
var ColorReset = "\033[0m"
View Source
var ColorWhite = "\033[97m"
View Source
var ColorYellow = "\033[33m"
View Source
var CyanBackground = "\033[46m"
View Source
var GrayBackground = "\033[47m"
View Source
var GreenBackground = "\033[42m"
View Source
var Purple = "\033[35m"
View Source
var PurpleBackground = "\033[45m"
View Source
var RedBackground = "\033[41m"
View Source
var WhiteBackground = "\033[107m"
View Source
var YellowBackground = "\033[43m"

Functions

func AddToLeft

func AddToLeft() slog.Attr

func AddToRight

func AddToRight() slog.Attr

func PanicMsgToString

func PanicMsgToString(msg interface{}) string

func StackTraceAttr

func StackTraceAttr(skipToFirstPanic bool, msg string) slog.Attr

func WithLogLevel

func WithLogLevel(lvl slog.Level) slog.Attr

Types

type AttrLevel

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

func (*AttrLevel) LogValue

func (c *AttrLevel) LogValue() slog.Value

type AttrOrder

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

func (*AttrOrder) LogValue

func (c *AttrOrder) LogValue() slog.Value

type ContextExtractor

type ContextExtractor interface {
	MergeContextAttrs(ctx context.Context, curAttrs []slog.Attr) []slog.Attr
}

type ControlAttr

type ControlAttr interface {
	slog.LogValuer
}

type NopLogger

type NopLogger struct {
	*slog.Logger
}

NopLogger This is a logger that does nothing, it's intended to be used in unit tests to suppress log messages.

func NewNopLogger

func NewNopLogger(lvl slog.Level) *NopLogger

type PinpointLogLevels

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

func NewPinpointLogLevels

func NewPinpointLogLevels() *PinpointLogLevels

func (*PinpointLogLevels) FindLevel

func (p *PinpointLogLevels) FindLevel(stackFramesToSkip int) (slog.Level, bool)

func (*PinpointLogLevels) LevelForLocation

func (p *PinpointLogLevels) LevelForLocation(loc string) (slog.Level, bool)

func (*PinpointLogLevels) PrintConfig

func (p *PinpointLogLevels) PrintConfig(c context.Context, l *slog.Logger)

func (*PinpointLogLevels) WithEnvironmentListOverrides

func (p *PinpointLogLevels) WithEnvironmentListOverrides(env []string) *PinpointLogLevels

func (*PinpointLogLevels) WithEnvironmentOverrides

func (p *PinpointLogLevels) WithEnvironmentOverrides() *PinpointLogLevels

func (*PinpointLogLevels) WithOverride

func (p *PinpointLogLevels) WithOverride(l slog.Level, packagePrefixes ...string) *PinpointLogLevels

type PrettySink

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

func NewPrettySink

func NewPrettySink(delegate io.Writer, lvl slog.Level, colorize bool) *PrettySink

func (*PrettySink) GetHandler

func (p *PrettySink) GetHandler() *slog.JSONHandler

func (*PrettySink) Write

func (p *PrettySink) Write(data []byte) (n int, err error)

type SinkingLogger

type SinkingLogger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

SinkingLogger This is a logger that writes messages to a memory buffer, it's intended to be used in unit tests to make sure that the log messages are expected. As a convenience feature to make it easier to match the messages, this logger also removes the timestamp from the log entries.

func NewJsonOrTextSinkingLogger

func NewJsonOrTextSinkingLogger(lvl slog.Level, textMode bool) *SinkingLogger

func NewSinkingLogger

func NewSinkingLogger(lvl slog.Level) *SinkingLogger

func (*SinkingLogger) Get

func (s *SinkingLogger) Get() string

Get returns the accumulated log data and resets the buffer

type SlogConvenience

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

func NewSlogConvenience

func NewSlogConvenience(opts SlogOptions, delegate slog.Handler) *SlogConvenience

func (*SlogConvenience) Enabled

func (s *SlogConvenience) Enabled(ctx context.Context, level slog.Level) bool

func (*SlogConvenience) Handle

func (s *SlogConvenience) Handle(ctx context.Context, record slog.Record) error

func (*SlogConvenience) WithAttrs

func (s *SlogConvenience) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SlogConvenience) WithGroup

func (s *SlogConvenience) WithGroup(name string) slog.Handler

type SlogOptions

type SlogOptions struct {
	AppendNewAttrsRight bool

	Pinpointer *PinpointLogLevels
	LogLevel   slog.Level
	Extractors []ContextExtractor
}

type StackElement

type StackElement struct {
	Msg string `json:"panic_msg,omitempty"`
	Fl  string `json:"fl,omitempty"`
	Fn  string `json:"fn,omitempty"`
}

type StackValue

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

func NewStackValue

func NewStackValue(skipFrames int, skipToFirstPanic bool, msg any) *StackValue

func (*StackValue) JSONStack

func (s *StackValue) JSONStack() []StackElement

JSONStack creates a nice stack trace, skipping all the deferred frames after the first panic() call. This method returns the list of structures that can be nicely reflected into JSON.

func (*StackValue) MarshalJSON

func (s *StackValue) MarshalJSON() ([]byte, error)

func (*StackValue) MarshalText

func (s *StackValue) MarshalText() (text []byte, err error)

MarshalText creates a nice stack trace, skipping all the deferred frames after the first panic() call. This method returns a human-readable multi-line string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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