log

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

README

structured logging

All usage of this package is the same as log/slog

install

go get github.com/RealFax/slog@latest

performance

you can use build tags to declare which JSON serialization method to use

e.g., use the jsoniter flag to declare the use of json-iterator/go

environment variables

LOG_PURE

type: boolean

This variable declares whether colorful output is disabled.

e.g., LOG_PURE=true

LOG_LEVEL

type: string

  • debug
  • info
  • warn
  • error

default: info e.g., LOG_LEVEL=debug || LOG_LEVEL=DEBUG

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ReleaseMode bool
)
View Source
var TimeFormat = "[15:04:05.000]"

Functions

func Debug

func Debug(msg string, args ...any)

func DebugContext

func DebugContext(ctx context.Context, msg string, args ...any)

func Default

func Default() *slog.Logger

func Error

func Error(msg string, args ...any)

func ErrorContext

func ErrorContext(ctx context.Context, msg string, args ...any)

func Info

func Info(msg string, args ...any)

func InfoContext

func InfoContext(ctx context.Context, msg string, args ...any)

func Log

func Log(ctx context.Context, level slog.Level, msg string, args ...any)

func LogAttrs

func LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)

func Marshal added in v1.0.1

func Marshal(v any) ([]byte, error)

func MarshalIndent added in v1.0.1

func MarshalIndent(v any, prefix, indent string) ([]byte, error)

func SetDefault

func SetDefault(l *slog.Logger)

func SetLogLoggerLevel

func SetLogLoggerLevel(level slog.Level) (oldLevel slog.Level)

func Warn

func Warn(msg string, args ...any)

func WarnContext

func WarnContext(ctx context.Context, msg string, args ...any)

func With

func With(args ...any) *slog.Logger

Types

type Attrs

type Attrs map[string]any

func (Attrs) String

func (a Attrs) String() string

type Color

type Color int32

func (Color) String

func (c Color) String() string

type Handler

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

func NewHandler

func NewHandler(opts *slog.HandlerOptions, w io.Writer) *Handler

func (*Handler) Enabled

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

func (*Handler) Handle

func (h *Handler) Handle(_ context.Context, record slog.Record) (err 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 Marshaler added in v1.0.1

type Marshaler = json.Marshaler

type RawMessage added in v1.0.1

type RawMessage = json.RawMessage

type Record

type Record struct {
	Group   string     `json:"group,omitempty"`
	Level   slog.Level `json:"level"`
	Time    time.Time  `json:"time"`
	Message string     `json:"message"`
	Attrs   Attrs      `json:"attrs"`
	Source  *string    `json:"source,omitempty"`
}

func (Record) Bytes

func (r Record) Bytes() []byte

Jump to

Keyboard shortcuts

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