xlog

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package xlog provides utilities for logging with context arguments. This package allows you to attach key-value pairs to a context, which can be used by the logging system to print additional information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithArgs

func ContextWithArgs(ctx context.Context, kvs ...any) context.Context

ContextWithArgs returns a context with key-values which myslog will print.

func Debug

func Debug(ctx context.Context, format string, args ...any)

func Error

func Error(ctx context.Context, format string, args ...any)

func Info

func Info(ctx context.Context, format string, args ...any)

func InitDefault

func InitDefault(opt Option)

func Warn

func Warn(ctx context.Context, format string, args ...any)

Types

type Logger

type Logger struct {
	*slog.Logger
}

func New

func New(opt Option) *Logger

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, format string, args ...any)

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, format string, args ...any)

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, format string, args ...any)

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, format string, args ...any)

type Option added in v0.0.9

type Option struct {
	Level      string `default:"info"`
	Writer     io.Writer
	Stdout     bool   `default:"false"`             // 仅当 Writer 为空时生效
	Path       string `default:"./log/default.log"` // 仅当 Writer 为空时生效
	MaxSizeMB  int    `default:"64"`                // 仅当 Writer 为空时生效
	MaxBackups int    `default:"100"`               // 仅当 Writer 为空时生效
	MaxDays    int    `default:"90"`                // 仅当 Writer 为空时生效
}

Jump to

Keyboard shortcuts

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