Documentation ¶
Index ¶
- Constants
- func Debug(msg string, args ...any)
- func Error(msg string, args ...any)
- func Info(msg string, args ...any)
- func NewMultiHandler(handlers ...slog.Handler) slog.Handler
- func SetDefault(logger *Logger)
- func Warn(msg string, args ...any)
- type Attr
- func Any(key string, val any) Attr
- func Bool(key string, val bool) Attr
- func BoolP(key string, val *bool) Attr
- func Duration(key string, val time.Duration) Attr
- func DurationP(key string, val *time.Duration) Attr
- func Err(err error) Attr
- func Float[F constraints.Float](key string, val F) Attr
- func Float32[F constraints.Float](key string, val F) Attr
- func Float32P[F constraints.Float](key string, val *F) Attr
- func Float64[F constraints.Float](key string, val F) Attr
- func Float64P[F constraints.Float](key string, val *F) Attr
- func FloatP[F constraints.Float](key string, val *F) Attr
- func Group(key string, args ...any) Attr
- func Int[I constraints.Int](key string, val I) Attr
- func Int16[I constraints.Int](key string, val I) Attr
- func Int16P[I constraints.Int](key string, val *I) Attr
- func Int32[I constraints.Int](key string, val I) Attr
- func Int32P[I constraints.Int](key string, val *I) Attr
- func Int64[I constraints.Int](key string, val I) Attr
- func Int64P[I constraints.Int](key string, val *I) Attr
- func Int8[I constraints.Int](key string, val I) Attr
- func Int8P[I constraints.Int](key string, val *I) Attr
- func IntP[I constraints.Int](key string, val *I) Attr
- func Skip(vs ...any) Attr
- func Stack(key string) Attr
- func StackData(key string, data []byte) Attr
- func String(key, val string) Attr
- func StringP(key string, val *string) Attr
- func Time(key string, val time.Time) Attr
- func TimeP(key string, val *time.Time) Attr
- func Uint[I constraints.Int](key string, val I) Attr
- func Uint16[I constraints.Int](key string, val I) Attr
- func Uint16P[I constraints.Int](key string, val *I) Attr
- func Uint32[I constraints.Int](key string, val I) Attr
- func Uint32P[I constraints.Int](key string, val *I) Attr
- func Uint64[I constraints.Int](key string, val I) Attr
- func Uint64P[I constraints.Int](key string, val *I) Attr
- func Uint8[I constraints.Int](key string, val I) Attr
- func Uint8P[I constraints.Int](key string, val *I) Attr
- func UintP[I constraints.Int](key string, val *I) Attr
- type AttrKey
- type CallerFormatter
- type ColorType
- type FunctionalLoggerProvider
- type GNetLogger
- func (l *GNetLogger) Debugf(format string, args ...interface{})
- func (l *GNetLogger) Errorf(format string, args ...interface{})
- func (l *GNetLogger) Fatalf(format string, args ...interface{})
- func (l *GNetLogger) Infof(format string, args ...interface{})
- func (l *GNetLogger) Warnf(format string, args ...interface{})
- type Handler
- type HandlerOption
- type HandlerOptions
- func (o *HandlerOptions) WithAttrKey(key AttrKey, value string) *HandlerOptions
- func (o *HandlerOptions) WithCaller(caller bool) *HandlerOptions
- func (o *HandlerOptions) WithCallerFormatter(formatter CallerFormatter) *HandlerOptions
- func (o *HandlerOptions) WithCallerSkip(skip int) *HandlerOptions
- func (o *HandlerOptions) WithColor(colorType ColorType, attrs ...color.Attribute) *HandlerOptions
- func (o *HandlerOptions) WithDelimiter(delimiter string) *HandlerOptions
- func (o *HandlerOptions) WithEnableColor(enable bool) *HandlerOptions
- func (o *HandlerOptions) WithErrTrackLevel(levels ...slog.Level) *HandlerOptions
- func (o *HandlerOptions) WithLevel(level Leveler) *HandlerOptions
- func (o *HandlerOptions) WithLevelStr(level slog.Level, str string) *HandlerOptions
- func (o *HandlerOptions) WithMessageFormatter(formatter MessageFormatter) *HandlerOptions
- func (o *HandlerOptions) WithTimeLayout(layout string) *HandlerOptions
- func (o *HandlerOptions) WithTrackBeautify(beautify bool) *HandlerOptions
- type Level
- type LevelVar
- type Leveler
- type Logger
- type LoggerProvider
- type MessageFormatter
- type MultiHandler
- type SilentHandler
Constants ¶
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError )
Variables ¶
This section is empty.
Functions ¶
func NewMultiHandler ¶
NewMultiHandler 创建一个新的多处理程序
Types ¶
type Attr ¶
func Float32P ¶
func Float32P[F constraints.Float](key string, val *F) Attr
Float32P 构造一个带有浮点值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func Float64P ¶
func Float64P[F constraints.Float](key string, val *F) Attr
Float64P 构造一个带有浮点值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func FloatP ¶
func FloatP[F constraints.Float](key string, val *F) Attr
FloatP 构造一个带有浮点值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func Int16P ¶
func Int16P[I constraints.Int](key string, val *I) Attr
Int16P 构造一个带有整数值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func Int32P ¶
func Int32P[I constraints.Int](key string, val *I) Attr
Int32P 构造一个带有整数值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func Int64P ¶
func Int64P[I constraints.Int](key string, val *I) Attr
Int64P 构造一个带有整数值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func Int8P ¶
func Int8P[I constraints.Int](key string, val *I) Attr
Int8P 构造一个带有整数值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func IntP ¶
func IntP[I constraints.Int](key string, val *I) Attr
IntP 构造一个带有整数值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func Uint16P ¶
func Uint16P[I constraints.Int](key string, val *I) Attr
Uint16P 构造一个带有整数值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func Uint32P ¶
func Uint32P[I constraints.Int](key string, val *I) Attr
Uint32P 构造一个带有整数值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
func Uint64P ¶
func Uint64P[I constraints.Int](key string, val *I) Attr
Uint64P 构造一个带有整数值的字段。返回的 Attr 将在适当的时候安全且显式地表示 "null"
type CallerFormatter ¶
type ColorType ¶
type ColorType uint16 // 日志颜色类型
const ( ColorTypeTime ColorType = iota + 1 // 时间颜色 ColorTypeDebugLevel // Debug 级别颜色 ColorTypeInfoLevel // Info 级别颜色 ColorTypeWarnLevel // Warn 级别颜色 ColorTypeErrorLevel // Error 级别颜色 ColorTypeCaller // 调用者颜色 ColorTypeMessage // 消息颜色 ColorTypeAttrKey // 属性键颜色 ColorTypeAttrValue // 属性值颜色 ColorTypeAttrDelimiter // 属性分隔符颜色 ColorTypeAttrErrorKey // 错误键颜色 ColorTypeAttrErrorValue // 错误值颜色 ColorTypeErrorTrack // 错误追踪颜色 ColorTypeErrorTrackHeader // 错误追踪头部颜色 )
type FunctionalLoggerProvider ¶
type FunctionalLoggerProvider func() *Logger
FunctionalLoggerProvider Logger 提供者
func (FunctionalLoggerProvider) Provide ¶
func (f FunctionalLoggerProvider) Provide() *Logger
Provide 提供 Logger
type GNetLogger ¶
type GNetLogger struct {
Logger *Logger
}
func NewGNetLogger ¶
func NewGNetLogger(logger *Logger) *GNetLogger
func (*GNetLogger) Debugf ¶
func (l *GNetLogger) Debugf(format string, args ...interface{})
func (*GNetLogger) Errorf ¶
func (l *GNetLogger) Errorf(format string, args ...interface{})
func (*GNetLogger) Fatalf ¶
func (l *GNetLogger) Fatalf(format string, args ...interface{})
func (*GNetLogger) Infof ¶
func (l *GNetLogger) Infof(format string, args ...interface{})
func (*GNetLogger) Warnf ¶
func (l *GNetLogger) Warnf(format string, args ...interface{})
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func NewHandler(w io.Writer, opts ...*HandlerOptions) *Handler
type HandlerOption ¶
type HandlerOption func(opts *HandlerOptions)
type HandlerOptions ¶
type HandlerOptions struct { TimeLayout string // 时间格式 ColorTypes map[ColorType]*color.Color // 颜色类型 EnableColor bool // 是否启用颜色 AttrKeys map[AttrKey]string // 属性键 Delimiter string // 分隔符 LevelStr map[Level]string // 日志级别字符串 Caller bool // 是否显示调用者 CallerSkip int // 调用者跳过层数 CallerFormatter CallerFormatter // 调用者格式化 MessageFormatter MessageFormatter // 消息格式化 ErrTrackLevel map[Level]struct{} // 错误追踪级别 TrackBeautify bool // 错误追踪美化 // contains filtered or unexported fields }
func NewDevGolandHandlerOptions ¶
func NewDevGolandHandlerOptions() *HandlerOptions
NewDevGolandHandlerOptions 创建一个适用于 Goland 开发环境的 HandlerOptions
- 与 NewDevHandlerOptions 不同的是,该可选项的日志级别会被输出为适用于 Goland 控制台色彩的字符串
func NewDevHandlerOptions ¶
func NewDevHandlerOptions() *HandlerOptions
NewDevHandlerOptions 创建一个适用于开发环境的 HandlerOptions
- 该可选项默认提供了一个具有色彩且日志级别为 slog.LevelDebug,并且具有对 error 类型的堆栈美化后的追踪的 HandlerOptions
func NewProdHandlerOptions ¶
func NewProdHandlerOptions() *HandlerOptions
NewProdHandlerOptions 创建一个适用于生产环境的 HandlerOptions
- 该可选项适用于在服务器上运行,该可选项与 NewDevHandlerOptions 相似,但是不包含任何色彩,且不包含对 error 的追踪,默认日志级别为 slog.LevelInfo
func NewTestHandlerOptions ¶
func NewTestHandlerOptions() *HandlerOptions
NewTestHandlerOptions 创建一个适用于测试环境的 HandlerOptions
- 该可选项适用于在服务器上运行,该可选项与 NewDevHandlerOptions 相似,但是不包含任何色彩
func (*HandlerOptions) WithAttrKey ¶
func (o *HandlerOptions) WithAttrKey(key AttrKey, value string) *HandlerOptions
WithAttrKey 设置属性键
func (*HandlerOptions) WithCaller ¶
func (o *HandlerOptions) WithCaller(caller bool) *HandlerOptions
WithCaller 设置是否显示调用者
func (*HandlerOptions) WithCallerFormatter ¶
func (o *HandlerOptions) WithCallerFormatter(formatter CallerFormatter) *HandlerOptions
WithCallerFormatter 设置调用者格式化
func (*HandlerOptions) WithCallerSkip ¶
func (o *HandlerOptions) WithCallerSkip(skip int) *HandlerOptions
WithCallerSkip 设置调用者跳过层数
func (*HandlerOptions) WithColor ¶
func (o *HandlerOptions) WithColor(colorType ColorType, attrs ...color.Attribute) *HandlerOptions
WithColor 设置日志颜色
func (*HandlerOptions) WithDelimiter ¶
func (o *HandlerOptions) WithDelimiter(delimiter string) *HandlerOptions
WithDelimiter 设置分隔符
func (*HandlerOptions) WithEnableColor ¶
func (o *HandlerOptions) WithEnableColor(enable bool) *HandlerOptions
WithEnableColor 设置是否启用颜色
func (*HandlerOptions) WithErrTrackLevel ¶
func (o *HandlerOptions) WithErrTrackLevel(levels ...slog.Level) *HandlerOptions
WithErrTrackLevel 设置错误追踪级别
func (*HandlerOptions) WithLevel ¶
func (o *HandlerOptions) WithLevel(level Leveler) *HandlerOptions
WithLevel 设置日志级别
func (*HandlerOptions) WithLevelStr ¶
func (o *HandlerOptions) WithLevelStr(level slog.Level, str string) *HandlerOptions
WithLevelStr 设置日志级别字符串
func (*HandlerOptions) WithMessageFormatter ¶
func (o *HandlerOptions) WithMessageFormatter(formatter MessageFormatter) *HandlerOptions
WithMessageFormatter 设置消息格式化
func (*HandlerOptions) WithTimeLayout ¶
func (o *HandlerOptions) WithTimeLayout(layout string) *HandlerOptions
WithTimeLayout 设置日志时间格式,如 "2006-01-02 15:04:05"
func (*HandlerOptions) WithTrackBeautify ¶
func (o *HandlerOptions) WithTrackBeautify(beautify bool) *HandlerOptions
WithTrackBeautify 设置错误追踪美化
type LoggerProvider ¶
type LoggerProvider interface { // Provide 提供 Logger Provide() *Logger }
LoggerProvider Logger 提供者
type MessageFormatter ¶
type MultiHandler ¶
type MultiHandler struct {
// contains filtered or unexported fields
}