Documentation
¶
Overview ¶
Package logger for log interface
Package logger 基于zap日志库,进行封装的logger库 支持日志自动切割
Index ¶
- func DPanic(ctx context.Context, msg string, fields ...interface{})
- func Debug(ctx context.Context, msg string, fields ...interface{})
- func Default(opts ...Option)
- func Error(ctx context.Context, msg string, fields ...interface{})
- func Fatal(ctx context.Context, msg string, fields ...interface{})
- func FieldToValue(f zap.Field) interface{}
- func Info(ctx context.Context, msg string, fields ...interface{})
- func MaskAllString(s string) string
- func MaskString(s string) string
- func Md5(str string) string
- func NewLogSugar(opts ...Option) *zap.SugaredLogger
- func Panic(ctx context.Context, msg string, fields ...interface{})
- func RandInt64(min, max int64) int64
- func Recover(ctx context.Context, msg string, fields ...interface{})
- func RndUUID() string
- func RndUUIDMd5() string
- func Uuid() string
- func Warn(ctx context.Context, msg string, fields ...interface{})
- type Logger
- type Option
- func WithAddCaller(b bool) Option
- func WithCallerSkip(skip int) Option
- func WithCompress(b bool) Option
- func WithCores(cores ...zapcore.Core) Option
- func WithEnableColor(b bool) Option
- func WithEnableSentry(b bool) Option
- func WithHostname(hostname string) Option
- func WithJsonFormat(b bool) Option
- func WithLogDir(dir string) Option
- func WithLogFilename(filename string) Option
- func WithLogLevel(level zapcore.Level) Option
- func WithMaxAge(d int) Option
- func WithMaxSize(size int) Option
- func WithSentryFlushTimeout(d time.Duration) Option
- func WithSentryLevel(level zapcore.Level) Option
- func WithStdout(b bool) Option
- func WithWriteToFile(b bool) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldToValue ¶ added in v1.3.3
FieldToValue 将zap field类型转换为 interface
func MaskString ¶ added in v1.3.3
MaskString 对字符串进行打码:保留前3位和后4位,中间替换为* 适用于长度在 7 位及以上的字符串(涵盖8-12位场景)
func NewLogSugar ¶
func NewLogSugar(opts ...Option) *zap.SugaredLogger
NewLogSugar zap log sugar语法糖 支持Debug,Info,Error,Panic,Warn,Fatal等方法 返回一个*zap.SugaredLogger
func RndUUID ¶
func RndUUID() string
RndUUID realizes unique uuid based on time ns and random number There is no duplication of uuid on a single machine If you want to generate non-duplicate uuid on a distributed architecture Just add some custom strings in front of rndStr Return format: eba1e8cd0460491049c644bdf3cf024d
Types ¶
type Logger ¶
type Logger interface {
// Debug debug级别日志
Debug(ctx context.Context, msg string, fields ...interface{})
// Info info级别日志
Info(ctx context.Context, msg string, fields ...interface{})
// Error 错误类型的日志
Error(ctx context.Context, msg string, fields ...interface{})
// Warn 警告类型的日志
Warn(ctx context.Context, msg string, fields ...interface{})
// DPanic 调试模式下的panic,程序不退出,继续运行
DPanic(ctx context.Context, msg string, fields ...interface{})
// Recover 用来捕获程序运行出现的panic信息,并记录到日志中
// 这个panic信息,将采用 DPanic 方法进行记录
Recover(ctx context.Context, msg string, fields ...interface{})
// Panic 抛出panic的时候,先记录日志,然后执行panic,退出当前goroutine
// 如果没有捕获,就会退出当前程序,建议程序做defer捕获处理
Panic(ctx context.Context, msg string, fields ...interface{})
// Fatal 抛出致命错误,然后退出程序
Fatal(ctx context.Context, msg string, fields ...interface{})
}
Logger interface.
type Option ¶
type Option func(z *zapLogWriter)
Option option for zapLogWriter
func WithCallerSkip ¶
WithCallerSkip 设置 skip addCaller = true,并且 callerSkip > 0 会设置zap.AddCallerSkip zap源码包中logger.go#260 check func check must always be called directly by a method in the Logger interface (e.g., Check, Info, Fatal). const callerSkipOffset = 2 这里的callerSkipOffset默认是2 如果基于这个Logger包,再包装一次,这个 skip = 2,以此类推 否则 skip=1
func WithEnableSentry ¶ added in v1.3.3
WithEnableSentry 是否开启sentry上报
func WithLogLevel ¶
WithLogLevel 日志级别,设置日志打印最低级别,如果不设置默认为info级别 zap.InfoLevel is the default logging priority.
func WithSentryFlushTimeout ¶ added in v1.3.3
WithSentryFlushTimeout 设置 sentry flush timeout
func WithSentryLevel ¶ added in v1.3.3
WithSentryLevel 设置 sentry 上报的 zap level
func WithWriteToFile ¶ added in v1.3.3
WithWriteToFile 设置日志是否写入文件中
