Documentation ¶
Overview ¶
Package tlog zap日志库的包装
Index ¶
- func Debug(msg string)
- func DebugContext(ctx context.Context, msg string)
- func DebugContextf(ctx context.Context, format string, args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(msg string)
- func ErrorContext(ctx context.Context, msg string)
- func ErrorContextf(ctx context.Context, format string, args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(msg string)
- func FatalContext(ctx context.Context, msg string)
- func FatalContextf(ctx context.Context, format string, args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(msg string)
- func InfoContext(ctx context.Context, msg string)
- func InfoContextf(ctx context.Context, format string, args ...interface{})
- func Infof(format string, args ...interface{})
- func Warn(msg string)
- func WarnContext(ctx context.Context, msg string)
- func WarnContextf(ctx context.Context, format string, args ...interface{})
- func Warnf(format string, args ...interface{})
- type Config
- type Fields
- type Logger
- func FromContext(ctx context.Context) (context.Context, Logger)
- func Named(name string) Logger
- func New(configs ...*Config) (Logger, error)
- func NewWithCallerSkip(skip int, configs ...*Config) (Logger, error)
- func ToContext(ctx context.Context, logger Logger) (context.Context, Logger)
- func WithContextField(ctx context.Context, key string, value interface{}) Logger
- func WithContextFields(ctx context.Context, fields Fields) Logger
- func WithError(err error) Logger
- func WithField(key string, value interface{}) Logger
- func WithFields(fields Fields) Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugContext ¶
DebugContext 打印Debug等级的日志,优先使用ctx中的logger
func DebugContextf ¶
DebugContextf 使用fmt.Sprintf打印Debug等级的日志,优先使用ctx中的logger
func ErrorContext ¶
ErrorContext 打印Error等级的日志,优先使用ctx中的logger
func ErrorContextf ¶
ErrorContextf 使用fmt.Sprintf打印Error等级的日志,优先使用ctx中的logger
func FatalContext ¶
FatalContext 打印Fatal等级的日志,优先使用ctx中的logger
func FatalContextf ¶
FatalContextf 使用fmt.Sprintf打印Fatal等级的日志,优先使用ctx中的logger
func InfoContext ¶
InfoContext 打印Info等级的日志,优先使用ctx中的logger
func InfoContextf ¶
InfoContextf 使用fmt.Sprintf打印Info等级的日志,优先使用ctx中的logger
func WarnContext ¶
WarnContext 打印Warn等级的日志,优先使用ctx中的logger
func WarnContextf ¶
WarnContextf 使用fmt.Sprintf打印Warn等级的日志,优先使用ctx中的logger
Types ¶
type Config ¶
type Config struct { Type string `yaml:"type"` // 日志类型:console/file Level string `yaml:"level"` // 日志等级:debug/info/warn/error/fatal // 以下配置仅在类型为file时生效 Prefix string `yaml:"prefix"` // 文件名前缀,例如prefix为tmp,则文件名为tmp.log MaxAge string `yaml:"max-age"` // 文件最大保存时间,使用time.ParseDuration函数进行计算 RotationTime string `yaml:"rotation-time"` // 文件切割时间间隔,使用time.ParseDuration函数进行计算 RotationSize int64 `yaml:"rotation-size"` // 文件最大大小,单位MB }
Config 日志配置
type Logger ¶
type Logger interface { // Debug 打印Debug等级的日志 Debug(msg string) // Info 打印Info等级的日志 Info(msg string) // Warn 打印Warn等级的日志 Warn(msg string) // Error 打印Error等级的日志 Error(msg string) // Fatal 打印Fatal等级的日志 Fatal(msg string) // Debugf 使用fmt.Sprintf打印Debug等级的日志 Debugf(template string, args ...interface{}) // Infof 使用fmt.Sprintf打印Info等级的日志 Infof(template string, args ...interface{}) // Warnf 使用fmt.Sprintf打印Warn等级的日志 Warnf(template string, args ...interface{}) // Errorf 使用fmt.Sprintf打印Error等级的日志 Errorf(template string, args ...interface{}) // Fatalf 使用fmt.Sprintf打印Fatal等级的日志 Fatalf(template string, args ...interface{}) // WithField 向日志增加一个自定义字段 WithField(key string, value interface{}) Logger // WithFields 向日志增加多个自定义字段 WithFields(fields Fields) Logger // WithError 向日志增加error错误类型字段 WithError(err error) Logger // Named 向日志器增加标题 Named(name string) Logger }
Logger 日志接口
func FromContext ¶
FromContext 从ctx中获取日志器,如果没有则创建新的日志器并返回新的context
func NewWithCallerSkip ¶
NewWithCallerSkip 创建新的日志器,额外加上skip调用者的个数
func WithContextField ¶
WithContextField 向ctx中的日志器中增加一个自定义字段,不会修改ctx中的日志器
func WithContextFields ¶
WithContextFields 向ctx中的日志器中增加多个自定义字段,不会修改ctx中的日志器