Documentation
¶
Index ¶
- Constants
- Variables
- func Countdown(msg string, seconds int)
- func Debug(msg string, args ...any)
- func Debugf(format string, args ...any)
- func DisableDLPLogger()
- func DisableJsonLogger()
- func DisableTextLogger()
- func Dynamic(msg string, frames int, interval int)
- func EnableDLPLogger()
- func EnableFormatters(formatters ...formatter.Formatter)
- func EnableJsonLogger()
- func EnableTextLogger()
- func Error(msg string, args ...any)
- func Errorf(format string, args ...any)
- func Fatal(msg string, args ...any)
- func Fatalf(format string, args ...any)
- func GetSlogLogger() *slog.Logger
- func Info(msg string, args ...any)
- func Infof(format string, args ...any)
- func IsDLPEnabled() bool
- func Loading(msg string, seconds int)
- func New(handler Handler) *slog.Logger
- func NewConsoleHandler(w io.Writer, noColor bool, opts *slog.HandlerOptions) slog.Handler
- func NewJSONHandler(w io.Writer, opts *HandlerOptions) *slog.JSONHandler
- func NewOptions(options *slog.HandlerOptions) *slog.HandlerOptions
- func NewTextHandler(w io.Writer, opts *HandlerOptions) *slog.TextHandler
- func NewWriter(filename ...string) *writer
- func Printf(format string, args ...any)
- func Println(msg string, args ...any)
- func Progress(msg string, durationMs int)
- func SetLevel(level any) error
- func SetLevelDebug()
- func SetLevelError()
- func SetLevelFatal()
- func SetLevelInfo()
- func SetLevelTrace()
- func SetLevelWarn()
- func Subscribe(size uint16) (<-chan slog.Record, context.CancelFunc)
- func Trace(msg string, args ...any)
- func Tracef(format string, args ...any)
- func Warn(msg string, args ...any)
- func Warnf(format string, args ...any)
- type Attr
- func Any(key string, v any) Attr
- func Bool(key string, v bool) Attr
- func Duration(key string, v time.Duration) Attr
- func Float64(key string, v float64) Attr
- func Group(key string, args ...any) Attr
- func Int(key string, v int) Attr
- func Int64(key string, v int64) Attr
- func String(key string, v string) Attr
- func Time(key string, v time.Time) Attr
- func Uint64(key string, v uint64) Attr
- type Fields
- type Handler
- type HandlerOptions
- type Level
- type Logger
- func (l *Logger) Countdown(msg string, seconds int)
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Dynamic(msg string, frames int, interval int)
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Fatal(msg string, args ...any)
- func (l *Logger) Fatalf(format string, args ...any)
- func (l *Logger) GetLevel() Level
- func (l *Logger) GetSlogLogger() *slog.Logger
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Loading(msg string, seconds int)
- func (l *Logger) Printf(format string, args ...any)
- func (l *Logger) Println(msg string, args ...any)
- func (l *Logger) Progress(msg string, durationMs int)
- func (l *Logger) SetLevel(level any) *Logger
- func (l *Logger) Trace(msg string, args ...any)
- func (l *Logger) Tracef(format string, args ...any)
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) Warnf(format string, args ...any)
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithContext(ctx context.Context) *Logger
- func (l *Logger) WithDeadline(d time.Time) (*Logger, context.CancelFunc)
- func (l *Logger) WithGroup(name string) *Logger
- func (l *Logger) WithTimeout(timeout time.Duration) (*Logger, context.CancelFunc)
- func (l *Logger) WithValue(key string, val interface{}) *Logger
- type Record
- type Subscriber
- type Value
Constants ¶
View Source
const ( TimeKey = slog.TimeKey LevelKey = slog.LevelKey MessageKey = slog.MessageKey SourceKey = slog.SourceKey )
View Source
const ( Name = "slog" Version = "v0.0.21" )
Variables ¶
View Source
var (
TimeFormat = "2006/01/02 15:04.05.000" // 默认时间格式
)
Functions ¶
func Dynamic ¶ added in v0.0.23
Dynamic 动态输出带点号动画效果
- msg: 要显示的消息内容
- frames: 动画更新的总帧数
- interval: 每次更新的时间间隔(毫秒)
func EnableFormatters ¶ added in v0.0.16
EnableFormatters 启用日志格式化器。
func GetSlogLogger ¶ added in v0.0.16
GetSlogLogger 返回原始log/slog的日志记录器
func NewConsoleHandler ¶ added in v0.0.2
NewConsoleHandler returns a log/slog.Handler using the receiver's options. Default options are used if opts is nil.
func NewJSONHandler ¶ added in v0.0.2
func NewJSONHandler(w io.Writer, opts *HandlerOptions) *slog.JSONHandler
func NewOptions ¶ added in v0.0.2
func NewOptions(options *slog.HandlerOptions) *slog.HandlerOptions
NewOptions 创建新的处理程序选项。
func NewTextHandler ¶ added in v0.0.2
func NewTextHandler(w io.Writer, opts *HandlerOptions) *slog.TextHandler
func NewWriter ¶ added in v0.0.19
func NewWriter(filename ...string) *writer
NewWriter 创建一个新的日志写入器,支持指定一个或多个文件路径,多个路径时使用第一个有效路径 filename: 日志文件路径 默认配置:
- 单个文件最大 100MB
- 保留最近 30 天的日志
- 最多保留 30 个备份文件
- 使用本地时间
- 不压缩旧文件
func SetLevel ¶ added in v0.0.23
SetLevel 动态更新日志级别 level 可以是数字(-8, -4, 0, 4, 8, 12)或字符串(trace, debug, info, warn, error, fatal)
Types ¶
type Fields ¶ added in v0.0.18
type Fields struct {
// contains filtered or unexported fields
}
Fields 存储上下文字段
type HandlerOptions ¶ added in v0.0.2
type HandlerOptions = slog.HandlerOptions
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger 结构体定义,实现日志记录功能
func WithGroup ¶ added in v0.0.11
WithGroup 创建一个带有指定组名的全局日志记录器 这是一个包级别的便捷方法 参数:
- name: 日志组的名称
返回:
- 带有指定组名的新日志记录器实例
func (*Logger) Dynamic ¶ added in v0.0.23
Dynamic 动态输出带点号动画效果
- msg: 要显示的消息内容
- frames: 动画更新的总帧数
- interval: 每次更新的时间间隔(毫秒)
func (*Logger) GetSlogLogger ¶ added in v0.0.16
GetSlogLogger 方法
func (*Logger) Progress ¶ added in v0.0.23
Progress 显示进度百分比
- msg: 要显示的消息内容
- durationMs: 从0%到100%的总持续时间(毫秒)
func (*Logger) WithContext ¶ added in v0.0.7
WithContext 创建带有上下文的新Logger
func (*Logger) WithDeadline ¶ added in v0.0.23
WithDeadline 创建带截止时间的Logger
func (*Logger) WithTimeout ¶ added in v0.0.23
WithTimeout 创建带超时的Logger
type Subscriber ¶ added in v0.0.23
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber 订阅者结构
Source Files
¶
Click to show internal directories.
Click to hide internal directories.