logging

package
v0.0.0-...-d8bc51a Latest Latest
Warning

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

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

Documentation

Overview

Package logging for dealing with logging, log settings and log format

Package logging for dealing with logging, log settings and log format

Inspiration:
	https://github.com/golang/example/tree/master/slog-handler-guide
	https://dusted.codes/creating-a-pretty-console-logger-using-gos-slog-package

Index

Constants

View Source
const ThisShouldNotHappenMessage = "this should not happen, please open an issue in issue tracker at https://github.com/9elements/firmware-action/issues"

ThisShouldNotHappenMessage contains a string which should be used in error message where the error justifies opening an issue in issue tracker

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(level slog.Level, opts ...PrettyHandlerOption)

InitLogger is used to initialize logger

func TrimNameFunction

func TrimNameFunction(pc uintptr) string

TrimNameFunction just trims the name

Types

type PrettyHandler

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

PrettyHandler is for prettier logs

func NewPrettyHandler

func NewPrettyHandler(output io.Writer, opts ...PrettyHandlerOption) *PrettyHandler

NewPrettyHandler returns a PrettyHandler

func (*PrettyHandler) Enabled

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

Enabled reports whether the handler handles records at the given level

func (*PrettyHandler) Handle

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

Handle handles the Record

func (*PrettyHandler) WithAttrs

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

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments

func (*PrettyHandler) WithGroup

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

WithGroup returns a new Handler with the given group appended to the receiver's existing groups

type PrettyHandlerOption

type PrettyHandlerOption func(*PrettyHandler)

PrettyHandlerOption is for functional option pattern

func WithIndent

func WithIndent(indent bool) PrettyHandlerOption

WithIndent enables or disables indentation (handy for programmatic processing out stderr)

func WithJSON

func WithJSON(json bool) PrettyHandlerOption

WithJSON enables or disables JSON output (handy for programmatic processing out stderr)

func WithLevel

func WithLevel(level slog.Level) PrettyHandlerOption

WithLevel changes log level

func WithSkipFrames

func WithSkipFrames(frames int) PrettyHandlerOption

WithSkipFrames changes how many stack frames to ascend in runtime.Caller()

0 = logging.(*PrettyHandler).Handle
1 = slog.(*Logger).log
2 = slog.Debug || slog.Info || slog.Warn || slog.Error
3 = place where we call slog.<LEVEL>

Jump to

Keyboard shortcuts

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