logging

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(format types.LogFormat, level types.LogLevel) (*slog.Logger, error)

Types

type Entry

type Entry struct {
	Time    time.Time  `json:"time"`
	Level   slog.Level `json:"level"`
	Message string     `json:"msg"`
	Error   string     `json:"error"`
	Raw     json.RawMessage
}

Entry is a convenience struct containing basic information TODO replace the fields with methods to save ram

func (Entry) Get

func (e Entry) Get(path string) gjson.Result

Use Get if you want to get a value from a LogEntry that is not contained within the message. Use the dot notation for that. For more information about dot notation see https://github.com/tidwall/gjson

func (Entry) GetMany

func (e Entry) GetMany(paths ...string) []gjson.Result

GetMany searches json for the multiple paths. The return value is a Result array where the number of items will be equal to the number of input paths. Use the dot notation for that. For more information about dot notation see https://github.com/tidwall/gjson

type Hook

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

Inspired by Logrus Testing Hook, this is my version for slog.

func NewHookLogger

func NewHookLogger(level slog.Level) (Hook, *slog.Logger)

func NewHookLoggerWithOptions

func NewHookLoggerWithOptions(options *slog.HandlerOptions) (Hook, *slog.Logger)

func (Hook) Logs

func (h Hook) Logs() []Entry

func (Hook) Reset

func (h Hook) Reset()

Clear the Hooks buffer, aka delete all Log Entries.

Jump to

Keyboard shortcuts

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