logger

package module
v0.0.0-...-48187bf Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 18 Imported by: 0

README

easy-logger

Documentation

Index

Constants

View Source
const (
	MaxInlineAttrsLength = 42
	JSONIndentSpaces     = " "
)
View Source
const (
	OTELTraceIDKey        = "trace_id"
	OTELSpanIDKey         = "span_id"
	OTELTraceFlagsKey     = "trace_flags"
	OTELServiceNameKey    = "service.name"
	OTELServiceVersionKey = "service.version"
	OTELResourceKey       = "resource"
	OTELScopeNameKey      = "scope.name"
	OTELScopeVersionKey   = "scope.version"
	OTELTimestampKey      = "timestamp"
	OTELSeverityTextKey   = "severity_text"
	OTELSeverityNumberKey = "severity_number"
	OTELBodyKey           = "body"
	OTELAttributesKey     = "attributes"
)
View Source
const AreaKey = "area"
View Source
const LevelFatal = slog.LevelError + 4
View Source
const LevelTrace = slog.LevelDebug - 4
View Source
const ProcessKey = "process"

Variables

This section is empty.

Functions

func Colouriser

func Colouriser(colourCode int, v string) string

func CreateLoggerFromEnv

func CreateLoggerFromEnv(out *os.File, colour string) *slog.Logger

func CreateLoggerSink

func CreateLoggerSink() *os.File

func CreateOTELLoggerFromEnv

func CreateOTELLoggerFromEnv(out *os.File, colour string) *slog.Logger

func NewDefaultResource

func NewDefaultResource() *resource.Resource

func PrettyLine

func PrettyLine(data map[string]any, colourise func(code int, value string) string) (string, error)

func SetProgramLevelPrettyLogger

func SetProgramLevelPrettyLogger(params PrettyLogParams) *slog.Logger

func Trace

func Trace(log *slog.Logger, msg string, data ...any)

Types

type Handler

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

func New

func New(handlerOptions *slog.HandlerOptions, options ...Option) *Handler

func NewHandler

func NewHandler(opts *slog.HandlerOptions, params PrettyLogParams, options ...Option) *Handler

func NewOTELHandler

func NewOTELHandler(opts *slog.HandlerOptions, params PrettyLogParams, options ...Option) *Handler

func (*Handler) Enabled

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

func (*Handler) Handle

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

func (*Handler) WithAttrs

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

func (*Handler) WithGroup

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

type InstrumentationScope

type InstrumentationScope struct {
	Name    string
	Version string
}

type Option

type Option func(h *Handler)

func WithColour

func WithColour() Option

func WithDestinationWriter

func WithDestinationWriter(writer io.Writer) Option

func WithInstrumentationScope

func WithInstrumentationScope(name, version string) Option

func WithOpenTelemetry

func WithOpenTelemetry() Option

func WithOutputEmptyAttrs

func WithOutputEmptyAttrs() Option

func WithResource

func WithResource(res *resource.Resource) Option

func WithTimestamp

func WithTimestamp() Option

type PrettyLogParams

type PrettyLogParams struct {
	Out   io.Writer
	Level slog.Level
}

func NewParams

func NewParams(out io.Writer) PrettyLogParams

Jump to

Keyboard shortcuts

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