xslog

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: MIT Imports: 6 Imported by: 0

README

xslog

Extend golang/slog with some utility functions.

Usage

This library requires go 1.21.0.

package main

import (
    "log/slog"
    "os"

    "github.com/gosolu/xslog"
)

func main() {
    handler := xslog.UseContext(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{}))
    slog.SetDefault(slog.New(handler))

    ctx := context.Background()
    slog.InfoContext(ctx, "Hi")
}
LICENSE

MIT LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendAttrs

func AppendAttrs(ctx context.Context, attrs ...slog.Attr) context.Context

AppendAttrs append attributes into context and create a new context

func AttrReplaces added in v0.1.1

func AttrReplaces(functions ...replaceFn) replaceFn

AttrReplaces bunch a group of replace functions into a single ReplaceAttr function

func LowerLevel added in v0.1.3

func LowerLevel(group []string, attr slog.Attr) slog.Attr

LowerLevel convert log level to lower

func NewHandler deprecated

func NewHandler(handler slog.Handler) slog.Handler

NewHandler create a new slog Handler with context support.

Deprecated: use UseContext instead

func SimpleSource added in v0.1.3

func SimpleSource(group []string, attr slog.Attr) slog.Attr

SimpleSource make log source shorter

func Stack added in v0.1.4

func Stack() string

Stack return current call stack

func UseContext added in v0.1.3

func UseContext(handler slog.Handler) slog.Handler

UseContext support add context attributes

Types

This section is empty.

Directories

Path Synopsis
Package stacktrace provides support for gathering stack traces efficiently.
Package stacktrace provides support for gathering stack traces efficiently.

Jump to

Keyboard shortcuts

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