Documentation ¶
Index ¶
- Constants
- func Any(key string, val any) slog.Attr
- func Bool(key string, val bool) slog.Attr
- func BoolP(key string, val *bool) slog.Attr
- func CallerBasicFormat(file string, line int) (repFile, refLine string)
- func DPanic(msg string, args ...any)
- func Debug(msg string, args ...any)
- func Duration(key string, val time.Duration) slog.Attr
- func DurationP(key string, val *time.Duration) slog.Attr
- func Err(err error) slog.Attr
- func Error(msg string, args ...any)
- func Fatal(msg string, args ...any)
- func Float[F generic.Float](key string, val F) slog.Attr
- func Float32[F generic.Float](key string, val F) slog.Attr
- func Float32P[F generic.Float](key string, val *F) slog.Attr
- func Float64[F generic.Float](key string, val F) slog.Attr
- func Float64P[F generic.Float](key string, val *F) slog.Attr
- func FloatP[F generic.Float](key string, val *F) slog.Attr
- func Group(key string, args ...any) slog.Attr
- func Info(msg string, args ...any)
- func Int[I generic.Integer](key string, val I) slog.Attr
- func Int16[I generic.Integer](key string, val I) slog.Attr
- func Int16P[I generic.Integer](key string, val *I) slog.Attr
- func Int32[I generic.Integer](key string, val I) slog.Attr
- func Int32P[I generic.Integer](key string, val *I) slog.Attr
- func Int64[I generic.Integer](key string, val I) slog.Attr
- func Int64P[I generic.Integer](key string, val *I) slog.Attr
- func Int8[I generic.Integer](key string, val I) slog.Attr
- func Int8P[I generic.Integer](key string, val *I) slog.Attr
- func IntP[I generic.Integer](key string, val *I) slog.Attr
- func NewHandler(w io.Writer, opts *Options) slog.Handler
- func NewMultiHandler(handlers ...slog.Handler) slog.Handler
- func Panic(msg string, args ...any)
- func SetDefault(l *Logger)
- func SetDefaultBySlog(l *slog.Logger)
- func Skip(vs ...any) slog.Attr
- func Stack(key string) slog.Attr
- func String(key, val string) slog.Attr
- func StringP(key string, val *string) slog.Attr
- func Time(key string, val time.Time) slog.Attr
- func TimeP(key string, val *time.Time) slog.Attr
- func Uint[I generic.Integer](key string, val I) slog.Attr
- func Uint16[I generic.Integer](key string, val I) slog.Attr
- func Uint16P[I generic.Integer](key string, val *I) slog.Attr
- func Uint32[I generic.Integer](key string, val I) slog.Attr
- func Uint32P[I generic.Integer](key string, val *I) slog.Attr
- func Uint64[I generic.Integer](key string, val I) slog.Attr
- func Uint64P[I generic.Integer](key string, val *I) slog.Attr
- func Uint8[I generic.Integer](key string, val I) slog.Attr
- func Uint8P[I generic.Integer](key string, val *I) slog.Attr
- func UintP[I generic.Integer](key string, val *I) slog.Attr
- func Warn(msg string, args ...any)
- type Field
- type Logger
- type MultiHandler
- type Option
- type Options
- func (o *Options) GerRuntimeHandler() *RuntimeHandler
- func (o *Options) With(opts ...*Options) *Options
- func (o *Options) WithCaller(enable bool, skip ...int) *Options
- func (o *Options) WithCallerColor(color string) *Options
- func (o *Options) WithCallerFormat(format func(file string, line int) (repFile, refLine string)) *Options
- func (o *Options) WithDev() *Options
- func (o *Options) WithDevMode(enable bool) *Options
- func (o *Options) WithDisableColor(disable bool) *Options
- func (o *Options) WithErrTrace(enable bool) *Options
- func (o *Options) WithErrTraceBeauty(enable bool) *Options
- func (o *Options) WithErrTraceColor(color string) *Options
- func (o *Options) WithErrorColor(color string) *Options
- func (o *Options) WithFieldPrefix(prefix string) *Options
- func (o *Options) WithKVDelimiter(delimiter string) *Options
- func (o *Options) WithKeyColor(color string) *Options
- func (o *Options) WithLevel(level slog.Leveler) *Options
- func (o *Options) WithLevelColor(level slog.Level, color string) *Options
- func (o *Options) WithLevelText(level slog.Level, text string) *Options
- func (o *Options) WithMessageColor(color string) *Options
- func (o *Options) WithProd() *Options
- func (o *Options) WithTest() *Options
- func (o *Options) WithTimeColor(color string) *Options
- func (o *Options) WithTimeLayout(layout string) *Options
- func (o *Options) WithTimePrefix(prefix string) *Options
- func (o *Options) WithTimePrefixColor(color string) *Options
- func (o *Options) WithTimePrefixDelimiter(delimiter string) *Options
- func (o *Options) WithTimePrefixDelimiterColor(color string) *Options
- func (o *Options) WithValueColor(color string) *Options
- type RuntimeHandler
Constants ¶
const ( ColorDefault = "\033[0m" // 默认 ColorDefaultBold = "\033[1m" // 默认加粗 ColorDefaultUnderline = "\033[4m" // 默认下划线 ColorDefaultReverse = "\033[7m" // 默认反显 ColorDefaultDelete = "\033[9m" // 默认删除线 ColorBlack = "\033[30m" // 黑色 ColorRed = "\033[31m" // 红色 ColorGreen = "\033[32m" // 绿色 ColorYellow = "\033[33m" // 黄色 ColorBlue = "\033[34m" // 蓝色 ColorPurple = "\033[35m" // 紫色 ColorCyan = "\033[36m" // 青色 ColorWhite = "\033[37m" // 白色 ColorBgBlack = "\033[40m" // 背景黑色 ColorBgRed = "\033[41m" // 背景红色 ColorBgGreen = "\033[42m" // 背景绿色 ColorBgYellow = "\033[43m" // 背景黄色 ColorBgBlue = "\033[44m" // 背景蓝色 ColorBgPurple = "\033[45m" // 背景紫色 ColorBgCyan = "\033[46m" // 背景青色 ColorBgWhite = "\033[47m" // 背景白色 ColorBrightBlack = "\033[90m" // 亮黑色 ColorBrightRed = "\033[91m" // 亮红色 ColorBrightGreen = "\033[92m" // 亮绿色 ColorBrightYellow = "\033[93m" // 亮黄色 ColorBrightBlue = "\033[94m" // 亮蓝色 ColorBrightPurple = "\033[95m" // 亮紫色 ColorBrightCyan = "\033[96m" // 亮青色 ColorBrightWhite = "\033[97m" // 亮白色 ColorBgBrightBlack = "\033[100m" // 背景亮黑色 ColorBgBrightRed = "\033[101m" // 背景亮红色 ColorBgBrightGreen = "\033[102m" // 背景亮绿色 ColorBgBrightYellow = "\033[103m" // 背景亮黄色 ColorBgBrightBlue = "\033[104m" // 背景亮蓝色 ColorBgBrightPurple = "\033[105m" // 背景亮紫色 ColorBgBrightCyan = "\033[106m" // 背景亮青色 ColorBgBrightWhite = "\033[107m" // 背景亮白色 ColorBlackBold = "\033[1;30m" // 黑色加粗 ColorRedBold = "\033[1;31m" // 红色加粗 ColorGreenBold = "\033[1;32m" // 绿色加粗 ColorYellowBold = "\033[1;33m" // 黄色加粗 ColorBlueBold = "\033[1;34m" // 蓝色加粗 ColorPurpleBold = "\033[1;35m" // 紫色加粗 ColorCyanBold = "\033[1;36m" // 青色加粗 ColorWhiteBold = "\033[1;37m" // 白色加粗 ColorBgBlackBold = "\033[1;40m" // 背景黑色加粗 ColorBgRedBold = "\033[1;41m" // 背景红色加粗 ColorBgGreenBold = "\033[1;42m" // 背景绿色加粗 ColorBgYellowBold = "\033[1;43m" // 背景黄色加粗 ColorBgBlueBold = "\033[1;44m" // 背景蓝色加粗 ColorBgPurpleBold = "\033[1;45m" // 背景紫色加粗 ColorBgCyanBold = "\033[1;46m" // 背景青色加粗 ColorBgWhiteBold = "\033[1;47m" // 背景白色加粗 ColorBrightBlackBold = "\033[1;90m" // 亮黑色加粗 ColorBrightRedBold = "\033[1;91m" // 亮红色加粗 ColorBrightGreenBold = "\033[1;92m" // 亮绿色加粗 ColorBrightYellowBold = "\033[1;93m" // 亮黄色加粗 ColorBrightBlueBold = "\033[1;94m" // 亮蓝色加粗 ColorBrightPurpleBold = "\033[1;95m" // 亮紫色加粗 ColorBrightCyanBold = "\033[1;96m" // 亮青色加粗 ColorBrightWhiteBold = "\033[1;97m" // 亮白色加粗 ColorBgBrightBlackBold = "\033[1;100m" // 背景亮黑色加粗 ColorBgBrightRedBold = "\033[1;101m" // 背景亮红色加粗 ColorBgBrightGreenBold = "\033[1;102m" // 背景亮绿色加粗 ColorBgBrightYellowBold = "\033[1;103m" // 背景亮黄色加粗 ColorBgBrightBlueBold = "\033[1;104m" // 背景亮蓝色加粗 ColorBgBrightPurpleBold = "\033[1;105m" // 背景亮紫色加粗 ColorBgBrightCyanBold = "\033[1;106m" // 背景亮青色加粗 ColorBgBrightWhiteBold = "\033[1;107m" // 背景亮白色加粗 ColorBlackUnderline = "\033[4;30m" // 黑色下划线 ColorRedUnderline = "\033[4;31m" // 红色下划线 ColorGreenUnderline = "\033[4;32m" // 绿色下划线 ColorYellowUnderline = "\033[4;33m" // 黄色下划线 ColorBlueUnderline = "\033[4;34m" // 蓝色下划线 ColorPurpleUnderline = "\033[4;35m" // 紫色下划线 ColorCyanUnderline = "\033[4;36m" // 青色下划线 ColorWhiteUnderline = "\033[4;37m" // 白色下划线 ColorBgBlackUnderline = "\033[4;40m" // 背景黑色下划线 ColorBgRedUnderline = "\033[4;41m" // 背景红色下划线 ColorBgGreenUnderline = "\033[4;42m" // 背景绿色下划线 ColorBgYellowUnderline = "\033[4;43m" // 背景黄色下划线 ColorBgBlueUnderline = "\033[4;44m" // 背景蓝色下划线 ColorBgPurpleUnderline = "\033[4;45m" // 背景紫色下划线 ColorBgCyanUnderline = "\033[4;46m" // 背景青色下划线 ColorBgWhiteUnderline = "\033[4;47m" // 背景白色下划线 ColorBrightBlackUnderline = "\033[4;90m" // 亮黑色下划线 ColorBrightRedUnderline = "\033[4;91m" // 亮红色下划线 ColorBrightGreenUnderline = "\033[4;92m" // 亮绿色下划线 ColorBrightYellowUnderline = "\033[4;93m" // 亮黄色下划线 ColorBrightBlueUnderline = "\033[4;94m" // 亮蓝色下划线 ColorBrightPurpleUnderline = "\033[4;95m" // 亮紫色下划线 ColorBrightCyanUnderline = "\033[4;96m" // 亮青色下划线 ColorBrightWhiteUnderline = "\033[4;97m" // 亮白色下划线 ColorBgBrightBlackUnderline = "\033[4;100m" // 背景亮黑色下划线 ColorBgBrightRedUnderline = "\033[4;101m" // 背景亮红色下划线 ColorBgBrightGreenUnderline = "\033[4;102m" // 背景亮绿色下划线 ColorBgBrightYellowUnderline = "\033[4;103m" // 背景亮黄色下划线 ColorBgBrightBlueUnderline = "\033[4;104m" // 背景亮蓝色下划线 ColorBgBrightPurpleUnderline = "\033[4;105m" // 背景亮紫色下划线 ColorBgBrightCyanUnderline = "\033[4;106m" // 背景亮青色下划线 ColorBgBrightWhiteUnderline = "\033[4;107m" // 背景亮白色下划线 ColorBlackReverse = "\033[7;30m" // 黑色反显 ColorRedReverse = "\033[7;31m" // 红色反显 ColorGreenReverse = "\033[7;32m" // 绿色反显 ColorYellowReverse = "\033[7;33m" // 黄色反显 ColorBlueReverse = "\033[7;34m" // 蓝色反显 ColorPurpleReverse = "\033[7;35m" // 紫色反显 ColorCyanReverse = "\033[7;36m" // 青色反显 ColorWhiteReverse = "\033[7;37m" // 白色反显 ColorBgBlackReverse = "\033[7;40m" // 背景黑色反显 ColorBgRedReverse = "\033[7;41m" // 背景红色反显 ColorBgGreenReverse = "\033[7;42m" // 背景绿色反显 ColorBgYellowReverse = "\033[7;43m" // 背景黄色反显 ColorBgBlueReverse = "\033[7;44m" // 背景蓝色反显 ColorBgPurpleReverse = "\033[7;45m" // 背景紫色反显 ColorBgCyanReverse = "\033[7;46m" // 背景青色反显 ColorBgWhiteReverse = "\033[7;47m" // 背景白色反显 ColorBrightBlackReverse = "\033[7;90m" // 亮黑色反显 ColorBrightRedReverse = "\033[7;91m" // 亮红色反显 ColorBrightGreenReverse = "\033[7;92m" // 亮绿色反显 ColorBrightYellowReverse = "\033[7;93m" // 亮黄色反显 ColorBrightBlueReverse = "\033[7;94m" // 亮蓝色反显 ColorBrightPurpleReverse = "\033[7;95m" // 亮紫色反显 ColorBrightCyanReverse = "\033[7;96m" // 亮青色反显 ColorBrightWhiteReverse = "\033[7;97m" // 亮白色反显 ColorBgBrightBlackReverse = "\033[7;100m" // 背景亮黑色反显 ColorBgBrightRedReverse = "\033[7;101m" // 背景亮红色反显 ColorBgBrightGreenReverse = "\033[7;102m" // 背景亮绿色反显 ColorBgBrightYellowReverse = "\033[7;103m" // 背景亮黄色反显 ColorBgBrightBlueReverse = "\033[7;104m" // 背景亮蓝色反显 ColorBgBrightPurpleReverse = "\033[7;105m" // 背景亮紫色反显 ColorBgBrightCyanReverse = "\033[7;106m" // 背景亮青色反显 ColorBgBrightWhiteReverse = "\033[7;107m" // 背景亮白色反显 StrikeThroughBlack = "\033[9;30m" // 黑色删除线 StrikeThroughRed = "\033[9;31m" // 红色删除线 StrikeThroughGreen = "\033[9;32m" // 绿色删除线 StrikeThroughYellow = "\033[9;33m" // 黄色删除线 StrikeThroughBlue = "\033[9;34m" // 蓝色删除线 StrikeThroughPurple = "\033[9;35m" // 紫色删除线 StrikeThroughCyan = "\033[9;36m" // 青色删除线 StrikeThroughWhite = "\033[9;37m" // 白色删除线 BgStrikeThroughBlack = "\033[9;40m" // 背景黑色删除线 BgStrikeThroughRed = "\033[9;41m" // 背景红色删除线 BgStrikeThroughGreen = "\033[9;42m" // 背景绿色删除线 BgStrikeThroughYellow = "\033[9;43m" // 背景黄色删除线 BgStrikeThroughBlue = "\033[9;44m" // 背景蓝色删除线 BgStrikeThroughPurple = "\033[9;45m" // 背景紫色删除线 BgStrikeThroughCyan = "\033[9;46m" // 背景青色删除线 BgStrikeThroughWhite = "\033[9;47m" // 背景白色删除线 BrightStrikeThroughBlack = "\033[9;90m" // 亮黑色删除线 BrightStrikeThroughRed = "\033[9;91m" // 亮红色删除线 BrightStrikeThroughGreen = "\033[9;92m" // 亮绿色删除线 BrightStrikeThroughYellow = "\033[9;93m" // 亮黄色删除线 BrightStrikeThroughBlue = "\033[9;94m" // 亮蓝色删除线 BrightStrikeThroughPurple = "\033[9;95m" // 亮紫色删除线 BrightStrikeThroughCyan = "\033[9;96m" // 亮青色删除线 BrightStrikeThroughWhite = "\033[9;97m" // 亮白色删除线 BgBrightStrikeThroughBlack = "\033[9;100m" // 背景亮黑色删除线 BgBrightStrikeThroughRed = "\033[9;101m" // 背景亮红色删除线 BgBrightStrikeThroughGreen = "\033[9;102m" // 背景亮绿色删除线 BgBrightStrikeThroughYellow = "\033[9;103m" // 背景亮黄色删除线 BgBrightStrikeThroughBlue = "\033[9;104m" // 背景亮蓝色删除线 BgBrightStrikeThroughPurple = "\033[9;105m" // 背景亮紫色删除线 BgBrightStrikeThroughCyan = "\033[9;106m" // 背景亮青色删除线 BgBrightStrikeThroughWhite = "\033[9;107m" // 背景亮白色删除线 )
const ( // DebugLevel 调试级别日志通常非常庞大,并且通常在生产中被禁用 DebugLevel = slog.LevelDebug // InfoLevel 是默认的日志记录优先级 InfoLevel = slog.LevelInfo // WarnLevel 日志比信息更重要,但不需要单独的人工审核 WarnLevel = slog.LevelWarn // ErrorLevel 日志具有高优先级。如果应用程序运行顺利,它不应该生成任何错误级别的日志 ErrorLevel = slog.LevelError // PanicLevel 记录一条消息,然后出现恐慌 PanicLevel slog.Level = 16 // DPanicLevel 日志是特别重要的错误。在开发中,记录器在写入消息后会出现恐慌 DPanicLevel slog.Level = 17 // FatalLevel 记录一条消息,然后调用 os.Exit(1) FatalLevel slog.Level = 20 )
const ( DefaultTimeLayout = time.DateTime DefaultTimePrefix = "" DefaultTimePrefixDelimiter = "=" DefaultCaller = true DefaultCallerSkip = 4 DefaultFieldPrefix = "" DefaultLevel = DebugLevel DefaultErrTrace = true DefaultErrTraceBeauty = true DefaultKVDelimiter = "=" DefaultDisableColor = false DefaultLevelInfoText = "INF" DefaultLevelWarnText = "WRN" DefaultLevelErrorText = "ERR" DefaultLevelDebugText = "DBG" DefaultLevelPanicText = "PNC" DefaultLevelDPanicText = "DPC" DefaultLevelFatalText = "FTL" DefaultDevMode = true DefaultTimePrefixColor = ColorDefault DefaultTimePrefixDelimiterColor = ColorDefault DefaultTimeColor = ColorDefaultBold DefaultLevelDebugColor = ColorBlue DefaultLevelInfoColor = ColorGreen DefaultLevelWarnColor = ColorBrightYellow DefaultLevelErrorColor = ColorRed DefaultLevelPanicColor = ColorBrightRed DefaultLevelDPanicColor = ColorBrightRed DefaultLevelFatalColor = ColorBrightRed DefaultCallerColor = ColorBrightBlueUnderline DefaultErrTraceColor = ColorBrightBlack DefaultKeyColor = ColorWhite DefaultValueColor = ColorDefault DefaultErrorColor = ColorRedBold DefaultMessageColor = ColorWhiteBold )
const (
ErrKey = "err"
)
Variables ¶
This section is empty.
Functions ¶
func CallerBasicFormat ¶ added in v0.4.4
CallerBasicFormat 返回调用者的基本格式
func DPanic ¶ added in v0.0.13
DPanic 在 DPanicLevel 记录一条消息。该消息包括在日志站点传递的任何字段以及记录器上累积的任何字段
- 如果记录器处于开发模式,它就会出现 panic(DPanic 的意思是“development panic”)。这对于捕获可恢复但不应该发生的错误很有用
- 该 panic 仅在 NewHandler 中创建的处理器会生效
func DurationP ¶ added in v0.0.13
DurationP 构造一个带有 time.Duration 的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
func Fatal ¶ added in v0.0.13
Fatal 在 FatalLevel 记录一条消息。该消息包括在日志站点传递的任何字段以及记录器上累积的任何字段
- 然后记录器调用 os.Exit(1),即使 FatalLevel 的日志记录被禁用
func NewHandler ¶ added in v0.4.4
NewHandler 创建一个更偏向于人类可读的处理程序,该处理程序也是默认的处理程序
func NewMultiHandler ¶ added in v0.4.4
NewMultiHandler 创建一个新的多处理程序
func Panic ¶ added in v0.0.13
Panic 在 PanicLevel 记录一条消息。该消息包括在日志站点传递的任何字段以及记录器上累积的任何字段
- 即使禁用了 PanicLevel 的日志记录,记录器也会出现 panic
func SetDefaultBySlog ¶ added in v0.5.0
SetDefaultBySlog 设置默认的日志记录器
Types ¶
type MultiHandler ¶ added in v0.4.4
type MultiHandler struct {
// contains filtered or unexported fields
}
type Options ¶ added in v0.4.4
type Options struct { TimeLayout string // 时间格式化字符串 TimePrefix string // 时间前缀 TimePrefixDelimiter string // 时间前缀分隔符 Caller bool // 是否显示调用者信息 CallerSkip int // 跳过的调用层数 CallerFormat func(file string, line int) (repFile, refLine string) // 调用者信息格式化函数 FieldPrefix string // 字段前缀 Level atomic.Value // 日志级别 ErrTrace bool // 是否显示错误堆栈 ErrTraceBeauty bool // 是否美化错误堆栈 KVDelimiter string // 键值对分隔符 DisableColor bool // 是否禁用颜色 TimePrefixColor string // 时间前缀颜色 TimePrefixDelimiterColor string // 时间前缀分隔符颜色 TimeColor string // 时间颜色 LevelText map[slog.Level]string // 日志级别文本 LevelColor map[slog.Level]string // 日志级别颜色 CallerColor string // 调用者信息颜色 ErrTraceColor string // 错误堆栈颜色 KeyColor string // 键颜色 ValueColor string // 值颜色 ErrorColor string // 错误颜色 MessageColor string // 消息颜色 DevMode bool // 是否为开发模式 // contains filtered or unexported fields }
Options 日志选项
func (*Options) GerRuntimeHandler ¶ added in v0.5.0
func (o *Options) GerRuntimeHandler() *RuntimeHandler
GerRuntimeHandler 获取运行时处理器
func (*Options) WithCaller ¶ added in v0.4.4
WithCaller 设置是否显示调用者信息
- 默认为 DefaultCaller,且跳过 DefaultCallerSkip 层调用
- 当存在多个 skip 参数时,取首个参数
func (*Options) WithCallerColor ¶ added in v0.4.4
WithCallerColor 设置调用者信息颜色
- 默认调用者信息颜色为 DefaultCallerColor
func (*Options) WithCallerFormat ¶ added in v0.4.4
func (o *Options) WithCallerFormat(format func(file string, line int) (repFile, refLine string)) *Options
WithCallerFormat 设置调用者信息格式化函数
- 默认格式化函数为 CallerBasicFormat
func (*Options) WithDevMode ¶ added in v0.4.4
WithDevMode 设置是否为开发模式
- 默认值为 DefaultDevMode
- 开发模式下将影响部分功能,例如 DPanic
func (*Options) WithDisableColor ¶ added in v0.4.4
WithDisableColor 设置是否禁用颜色
- 默认为 DefaultDisableColor
func (*Options) WithErrTrace ¶ added in v0.4.4
WithErrTrace 设置是否显示错误堆栈
- 默认为 DefaultErrTrace
- 当启用错误堆栈追踪时,一切 error 字段都会转换为包含错误信息和堆栈信息的组信息
func (*Options) WithErrTraceBeauty ¶ added in v0.4.4
WithErrTraceBeauty 设置是否美化错误堆栈
- 默认为 DefaultErrTraceBeauty
- 当启用错误堆栈追踪时,一切 error 字段都会转换为包含错误信息和堆栈信息的组信息
func (*Options) WithErrTraceColor ¶ added in v0.4.4
WithErrTraceColor 设置错误堆栈颜色
- 默认错误堆栈颜色为 DefaultErrTraceColor
func (*Options) WithFieldPrefix ¶ added in v0.4.4
WithFieldPrefix 为所有字段设置前缀
- 默认字段前缀为 DefaultFieldPrefix
- 字段前缀为空时,不会添加字段前缀
- 假设字段前缀为 "M",假设原本输出为 "ID=1",则日志输出为 "MID=1
func (*Options) WithKVDelimiter ¶ added in v0.4.4
WithKVDelimiter 设置键值对分隔符
- 默认键值对分隔符为 DefaultKVDelimiter
func (*Options) WithLevelColor ¶ added in v0.4.4
WithLevelColor 设置日志级别颜色
- 默认日志级别颜色为 DefaultLevelInfoColor, DefaultLevelWarnColor, DefaultLevelErrorColor, DefaultLevelDebugColor, DefaultLevelPanicColor, DefaultLevelDPanicColor, DefaultLevelFatalColor
func (*Options) WithLevelText ¶ added in v0.4.4
WithLevelText 设置日志级别文本
- 默认日志级别文本为 DefaultLevelInfoText, DefaultLevelWarnText, DefaultLevelErrorText, DefaultLevelDebugText, DefaultLevelPanicText, DefaultLevelDPanicText, DefaultLevelFatalText
func (*Options) WithMessageColor ¶ added in v0.4.4
WithMessageColor 设置消息颜色
- 默认消息颜色为 DefaultMessageColor
func (*Options) WithTest ¶ added in v0.4.4
WithTest 设置可选项为测试模式
- 测试模式适用于测试环境,测试环境与开发环境相似,但是会屏蔽掉一些不必要的信息
func (*Options) WithTimeLayout ¶ added in v0.4.4
WithTimeLayout 设置时间格式化字符串
- 默认时间格式化字符串为 DefaultTimeLayout
- 假设时间格式化字符串为 "2006-01-02 15:04:05",则日志输出为 "2020-01-01 00:00:00 ..."
func (*Options) WithTimePrefix ¶ added in v0.4.4
WithTimePrefix 设置时间前缀
- 默认时间前缀为 DefaultTimePrefix
- 时间前缀为空时,不会添加时间前缀
- 假设时间前缀为 "TIME=",则日志输出为 "TIME=2020-01-01 00:00:00 ..."
func (*Options) WithTimePrefixColor ¶ added in v0.4.4
WithTimePrefixColor 设置时间前缀颜色
- 默认时间前缀颜色为 DefaultTimePrefixColor
func (*Options) WithTimePrefixDelimiter ¶ added in v0.4.4
WithTimePrefixDelimiter 设置时间前缀分隔符
- 默认时间前缀分隔符为 DefaultTimePrefixDelimiter
func (*Options) WithTimePrefixDelimiterColor ¶ added in v0.4.4
WithTimePrefixDelimiterColor 设置时间前缀分隔符颜色
- 默认时间前缀分隔符颜色为 DefaultTimePrefixDelimiterColor
type RuntimeHandler ¶ added in v0.5.0
type RuntimeHandler struct {
// contains filtered or unexported fields
}
func (*RuntimeHandler) ChangeLevel ¶ added in v0.5.0
func (h *RuntimeHandler) ChangeLevel(level slog.Leveler)
ChangeLevel 改变日志级别
func (*RuntimeHandler) Level ¶ added in v0.5.0
func (h *RuntimeHandler) Level() slog.Level
Level 获取日志级别