log

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug 使用全局日志记录器在 LevelDebug 级别下记录一条消息

func Error

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

Error 使用全局日志记录器在 LevelError 级别下记录一条消息

func Info

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

Info 使用全局日志记录器在 LevelInfo 级别下记录一条消息

func Log

func Log(level Level, msg string, args ...any)

Log 按照指定级别记录日志消息

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) slog.Handler

NewMultiHandler 创建一个新的多处理程序

func ResetLogger

func ResetLogger()

ResetLogger 并发安全的重置全局日志记录器

func SetLogger

func SetLogger(l *Logger)

SetLogger 并发安全的设置全局日志记录器

func Warn

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

Warn 使用全局日志记录器在 LevelWarn 级别下记录一条消息

Types

type AttrType

type AttrType int
const (
	AttrTypeTime AttrType = iota + 1
	AttrTypeCaller
	AttrTypeMessage
	AttrTypeField
	AttrTypeTrace
	AttrTypeError
)

type Attribute

type Attribute = color.Attribute
const (
	ColorReset Attribute = iota
	ColorBold
	ColorFaint
	ColorItalic
	ColorUnderline
	ColorBlinkSlow
	ColorBlinkRapid
	ColorReverseVideo
	ColorConcealed
	ColorCrossedOut
)

Base attributes

const (
	ColorResetBold Attribute = iota + 22
	ColorResetItalic
	ColorResetUnderline
	ColorResetBlinking

	ColorResetReversed
	ColorResetConcealed
	ColorResetCrossedOut
)
const (
	ColorFgBlack Attribute = iota + 30
	ColorFgRed
	ColorFgGreen
	ColorFgYellow
	ColorFgBlue
	ColorFgMagenta
	ColorFgCyan
	ColorFgWhite
)

Foreground text colors

const (
	ColorFgHiBlack Attribute = iota + 90
	ColorFgHiRed
	ColorFgHiGreen
	ColorFgHiYellow
	ColorFgHiBlue
	ColorFgHiMagenta
	ColorFgHiCyan
	ColorFgHiWhite
)

Foreground Hi-Intensity text colors

const (
	ColorBgBlack Attribute = iota + 40
	ColorBgRed
	ColorBgGreen
	ColorBgYellow
	ColorBgBlue
	ColorBgMagenta
	ColorBgCyan
	ColorBgWhite
)

Background text colors

const (
	ColorBgHiBlack Attribute = iota + 100
	ColorBgHiRed
	ColorBgHiGreen
	ColorBgHiYellow
	ColorBgHiBlue
	ColorBgHiMagenta
	ColorBgHiCyan
	ColorBgHiWhite
)

Background Hi-Intensity text colors

type Color

type Color struct {
	*color.Color
	// contains filtered or unexported fields
}

func NewColor

func NewColor(attributes ...Attribute) *Color

func (*Color) Add

func (c *Color) Add(value ...Attribute) *Color

type Field

type Field = slog.Attr

func Any

func Any(key string, val any) Field

Any 构造一个带有任意值的字段

func Bool

func Bool(key string, val bool) Field

Bool 构造一个带有布尔值的字段

func BoolP

func BoolP(key string, val *bool) Field

BoolP 构造一个带有布尔值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Duration

func Duration(key string, val time.Duration) Field

Duration 使用给定的键和值构造一个字段。编码器控制持续时间的序列化方式

func DurationP

func DurationP(key string, val *time.Duration) Field

DurationP 构造一个带有 time.Duration 的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Err

func Err(err error) Field

Err 构造一个带有错误值的字段

func Float

func Float[F generic.Float](key string, val F) Field

Float 构造一个带有浮点值的字段

func Float32

func Float32[F generic.Float](key string, val F) Field

Float32 构造一个带有浮点值的字段

func Float32P

func Float32P[F generic.Float](key string, val *F) Field

Float32P 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Float64

func Float64[F generic.Float](key string, val F) Field

Float64 构造一个带有浮点值的字段

func Float64P

func Float64P[F generic.Float](key string, val *F) Field

Float64P 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func FloatP

func FloatP[F generic.Float](key string, val *F) Field

FloatP 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Group

func Group(key string, args ...any) Field

Group 返回分组字段

func Int

func Int[I generic.Integer](key string, val I) Field

Int 构造一个带有整数值的字段

func Int16

func Int16[I generic.Integer](key string, val I) Field

Int16 构造一个带有整数值的字段

func Int16P

func Int16P[I generic.Integer](key string, val *I) Field

Int16P 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Int32

func Int32[I generic.Integer](key string, val I) Field

Int32 构造一个带有整数值的字段

func Int32P

func Int32P[I generic.Integer](key string, val *I) Field

Int32P 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Int64

func Int64[I generic.Integer](key string, val I) Field

Int64 构造一个带有整数值的字段

func Int64P

func Int64P[I generic.Integer](key string, val *I) Field

Int64P 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Int8

func Int8[I generic.Integer](key string, val I) Field

Int8 构造一个带有整数值的字段

func Int8P

func Int8P[I generic.Integer](key string, val *I) Field

Int8P 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func IntP

func IntP[I generic.Integer](key string, val *I) Field

IntP 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Skip

func Skip(vs ...any) Field

Skip 构造一个无操作字段,这在处理其他 Field 构造函数中的无效输入时通常很有用

  • 该函数还支持将其他字段快捷的转换为 Skip 字段

func Stack

func Stack(key string) Field

Stack 返回堆栈字段

func String

func String(key, val string) Field

String 构造一个带有字符串值的字段

func StringP

func StringP(key string, val *string) Field

StringP 构造一个带有字符串值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Time

func Time(key string, val time.Time) Field

Time 构造一个带有时间值的字段

func TimeP

func TimeP(key string, val *time.Time) Field

TimeP 构造一个带有时间值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Uint

func Uint[I generic.Integer](key string, val I) Field

Uint 构造一个带有整数值的字段

func Uint16

func Uint16[I generic.Integer](key string, val I) Field

Uint16 构造一个带有整数值的字段

func Uint16P

func Uint16P[I generic.Integer](key string, val *I) Field

Uint16P 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Uint32

func Uint32[I generic.Integer](key string, val I) Field

Uint32 构造一个带有整数值的字段

func Uint32P

func Uint32P[I generic.Integer](key string, val *I) Field

Uint32P 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Uint64

func Uint64[I generic.Integer](key string, val I) Field

Uint64 构造一个带有整数值的字段

func Uint64P

func Uint64P[I generic.Integer](key string, val *I) Field

Uint64P 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func Uint8

func Uint8[I generic.Integer](key string, val I) Field

Uint8 构造一个带有整数值的字段

func Uint8P

func Uint8P[I generic.Integer](key string, val *I) Field

Uint8P 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

func UintP

func UintP[I generic.Integer](key string, val *I) Field

UintP 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

type Handler

type Handler = slog.Handler

type Level

type Level = slog.Level
const (
	LevelDebug Level = slog.LevelDebug
	LevelInfo  Level = slog.LevelInfo
	LevelWarn  Level = slog.LevelWarn
	LevelError Level = slog.LevelError
)

func Levels

func Levels() []Level

type Logger

type Logger = slog.Logger

func GetLogger

func GetLogger() *Logger

GetLogger 并发安全的获取当前全局日志记录器

func NewDefaultLogger

func NewDefaultLogger() *Logger

NewDefaultLogger 创建一个新的默认日志记录器

func NewLogger

func NewLogger(handler Handler) *Logger

NewLogger 创建一个新的日志记录器

type MinotaurHandler

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

func NewHandler

func NewHandler(w io.Writer, opts ...*Options) *MinotaurHandler

func (*MinotaurHandler) Enabled

func (h *MinotaurHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*MinotaurHandler) GetOptions

func (h *MinotaurHandler) GetOptions() *Options

func (*MinotaurHandler) Handle

func (h *MinotaurHandler) Handle(ctx context.Context, record slog.Record) (err error)

func (*MinotaurHandler) WithAttrs

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

func (*MinotaurHandler) WithGroup

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

type MultiHandler

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

func (MultiHandler) Enabled

func (h MultiHandler) Enabled(ctx context.Context, level slog.Level) bool

func (MultiHandler) Handle

func (h MultiHandler) Handle(ctx context.Context, record slog.Record) (err error)

func (MultiHandler) WithAttrs

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

func (MultiHandler) WithGroup

func (h MultiHandler) WithGroup(name string) slog.Handler

type Options

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

func DefaultOptions

func DefaultOptions() *Options

func (*Options) Apply

func (opt *Options) Apply(opts ...*Options) *Options

func (*Options) GetAttrDelimiter

func (opt *Options) GetAttrDelimiter(attrType AttrType) string

GetAttrDelimiter 获取属性分隔符

func (*Options) GetAttrDelimiterColor

func (opt *Options) GetAttrDelimiterColor(attrType AttrType) *Color

GetAttrDelimiterColor 获取属性分隔符颜色

func (*Options) GetAttrPrefix

func (opt *Options) GetAttrPrefix(attrType AttrType) string

GetAttrPrefix 获取属性前缀

func (*Options) GetAttrPrefixColor

func (opt *Options) GetAttrPrefixColor(attrType AttrType) *Color

GetAttrPrefixColor 获取属性前缀颜色

func (*Options) GetAttrTextColor

func (opt *Options) GetAttrTextColor(attrType AttrType) *Color

GetAttrTextColor 获取属性前缀颜色

func (*Options) GetCallerFormatter

func (opt *Options) GetCallerFormatter() func(file string, line int) (repFile, repLine string)

GetCallerFormatter 获取调用者格式化函数

func (*Options) GetCallerSkip

func (opt *Options) GetCallerSkip() int

GetCallerSkip 获取调用者跳过数量

func (*Options) GetLevel

func (opt *Options) GetLevel() Level

GetLevel 获取当前日志级别

func (*Options) GetLevelColor

func (opt *Options) GetLevelColor(level Level) *Color

GetLevelColor 获取日志级别颜色

func (*Options) GetLevelText

func (opt *Options) GetLevelText(level Level) string

GetLevelText 获取日志级别文本

func (*Options) GetStackTrace

func (opt *Options) GetStackTrace(level Level) bool

GetStackTrace 获取堆栈追踪

func (*Options) GetStackTraceBeauty

func (opt *Options) GetStackTraceBeauty(level Level) bool

GetStackTraceBeauty 获取堆栈追踪是否美化

func (*Options) GetTimeLayout

func (opt *Options) GetTimeLayout() string

GetTimeLayout 获取当前日志的时间布局

func (*Options) IsDisabledCaller

func (opt *Options) IsDisabledCaller() bool

IsDisabledCaller 获取是否已经禁用调用者

func (*Options) IsDisabledColor

func (opt *Options) IsDisabledColor() bool

IsDisabledColor 获取是否已经禁用颜色

func (*Options) WithAttrDelimiter

func (opt *Options) WithAttrDelimiter(attrType AttrType, delimiter string) *Options

WithAttrDelimiter 设置属性分隔符

  • 该函数支持运行时设置

func (*Options) WithAttrDelimiterColor

func (opt *Options) WithAttrDelimiterColor(attrType AttrType, color *Color) *Options

WithAttrDelimiterColor 设置属性分隔符颜色

  • 该函数支持运行时设置

func (*Options) WithAttrPrefix

func (opt *Options) WithAttrPrefix(attrType AttrType, prefix string) *Options

WithAttrPrefix 设置属性前缀

  • 该函数支持运行时设置

func (*Options) WithAttrPrefixColor

func (opt *Options) WithAttrPrefixColor(attrType AttrType, color *Color) *Options

WithAttrPrefixColor 设置属性前缀颜色

  • 该函数支持运行时设置

func (*Options) WithAttrTextColor

func (opt *Options) WithAttrTextColor(attrType AttrType, color *Color) *Options

WithAttrTextColor 设置属性文本颜色

  • 该函数支持运行时设置

func (*Options) WithCallerFormatter

func (opt *Options) WithCallerFormatter(formatter func(file string, line int) (repFile, repLine string)) *Options

WithCallerFormatter 设置调用者格式化函数

  • 该函数支持运行时设置

func (*Options) WithCallerSkip

func (opt *Options) WithCallerSkip(skip int) *Options

WithCallerSkip 设置调用者跳过数量

  • 该函数支持运行时设置

func (*Options) WithDisableCaller

func (opt *Options) WithDisableCaller(disable bool) *Options

WithDisableCaller 设置是否禁用调用者

  • 该函数支持运行时设置

func (*Options) WithDisableColor

func (opt *Options) WithDisableColor(disable bool) *Options

WithDisableColor 设置禁用颜色

  • 该函数支持运行时设置

func (*Options) WithLevel

func (opt *Options) WithLevel(level Level) *Options

WithLevel 设置日志级别

  • 该函数支持运行时设置

func (*Options) WithLevelColor

func (opt *Options) WithLevelColor(level Level, color *Color) *Options

WithLevelColor 设置日志级别颜色

  • 该函数支持运行时设置

func (*Options) WithLevelText

func (opt *Options) WithLevelText(level Level, text string) *Options

WithLevelText 设置日志级别文本

  • 该函数支持运行时设置

func (*Options) WithStackTrace

func (opt *Options) WithStackTrace(level Level, enable bool) *Options

WithStackTrace 设置堆栈追踪,当日志记录器中包含 error 时,将会打印堆栈信息

  • 该函数支持运行时设置

func (*Options) WithStackTraceBeauty

func (opt *Options) WithStackTraceBeauty(level Level, enable bool) *Options

WithStackTraceBeauty 设置堆栈追踪美化

  • 该函数支持运行时设置

func (*Options) WithTimeLayout

func (opt *Options) WithTimeLayout(layout string) *Options

WithTimeLayout 设置日志的时间布局,默认为 time.DateTime

  • 该函数支持运行时设置

Jump to

Keyboard shortcuts

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