Documentation
¶
Index ¶
- Constants
- func Debug(message string)
- func DebugCtx(ctx context.Context, message string)
- func DebugCtxF(ctx context.Context, format string, args ...interface{})
- func DebugCtxWithFields(ctx context.Context, message string, fields Fields)
- func DebugF(format string, args ...interface{})
- func DebugWithFields(message string, fields Fields)
- func Error(message string)
- func ErrorCtx(ctx context.Context, message string)
- func ErrorCtxF(ctx context.Context, format string, args ...interface{})
- func ErrorCtxWithFields(ctx context.Context, message string, fields Fields)
- func ErrorF(format string, args ...interface{})
- func ErrorWithFields(message string, fields Fields)
- func Fatal(message string)
- func FatalCtx(ctx context.Context, message string)
- func FatalCtxF(ctx context.Context, format string, args ...interface{})
- func FatalCtxWithFields(ctx context.Context, message string, fields Fields)
- func FatalF(format string, args ...interface{})
- func FatalWithFields(message string, fields Fields)
- func Info(message string)
- func InfoCtx(ctx context.Context, message string)
- func InfoCtxF(ctx context.Context, format string, args ...interface{})
- func InfoCtxWithFields(ctx context.Context, message string, fields Fields)
- func InfoF(format string, args ...interface{})
- func InfoWithFields(message string, fields Fields)
- func Panic(message string)
- func PanicCtx(ctx context.Context, message string)
- func PanicCtxF(ctx context.Context, format string, args ...interface{})
- func PanicCtxWithFields(ctx context.Context, message string, fields Fields)
- func PanicF(format string, args ...interface{})
- func PanicWithFields(message string, fields Fields)
- func SetLevel(level Level)
- func Warn(message string)
- func WarnCtx(ctx context.Context, message string)
- func WarnCtxF(ctx context.Context, format string, args ...interface{})
- func WarnCtxWithFields(ctx context.Context, message string, fields Fields)
- func WarnF(format string, args ...interface{})
- func WarnWithFields(message string, fields Fields)
- func WithLogger(ctx context.Context, logger *Logger) context.Context
- type Config
- type EncoderConfig
- type Fields
- type Level
- type Logger
- func (l *Logger) AddCallerSkip(skip int) *Logger
- func (l *Logger) Debug(message string)
- func (l *Logger) DebugF(format string, args ...interface{})
- func (l *Logger) DebugWithField(message string, fields Fields)
- func (l *Logger) Error(message string)
- func (l *Logger) ErrorF(format string, args ...interface{})
- func (l *Logger) ErrorWithField(message string, fields Fields)
- func (l *Logger) Fatal(message string)
- func (l *Logger) FatalF(format string, args ...interface{})
- func (l *Logger) FatalWithField(message string, fields Fields)
- func (l *Logger) Info(message string)
- func (l *Logger) InfoF(format string, args ...interface{})
- func (l *Logger) InfoWithField(message string, fields Fields)
- func (l *Logger) NewNamespace(name string) *Logger
- func (l *Logger) Panic(message string)
- func (l *Logger) PanicF(format string, args ...interface{})
- func (l *Logger) PanicWithField(message string, fields Fields)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetLevelHandler(w http.ResponseWriter, r *http.Request)
- func (l *Logger) SetName(name string) *Logger
- func (l *Logger) Sync()
- func (l *Logger) Warn(message string)
- func (l *Logger) WarnF(format string, args ...interface{})
- func (l *Logger) WarnWithField(message string, fields Fields)
- func (l *Logger) WithError(err error) *Logger
- func (l *Logger) WithField(key string, value interface{}) *Logger
- func (l *Logger) WithLogId(id string) *Logger
- func (l *Logger) WithOutFile(outputPaths []string, level Level) (*Logger, func(), error)
- func (l *Logger) WithOutput(writer io.Writer, level Level, format string) *Logger
- func (l *Logger) WithSampling(opts *SamplingOption) *Logger
- func (l *Logger) WithScope(scope string) *Logger
- type Options
- type RotateWriter
- type SamplingOption
Constants ¶
const ( // JSONFormat 以 JSON 形式输出 JSONFormat = "json" // TextFormat 以 TEXT 形式输出 TextFormat = "console" )
日志输出格式
const ( DebugLevel = zap.DebugLevel InfoLevel = zap.InfoLevel WarnLevel = zap.WarnLevel ErrorLevel = zap.ErrorLevel PanicLevel = zap.PanicLevel FatalLevel = zap.FatalLevel )
const ( IdKey = "@logId" ErrorKey = "@error" ScopeKey = "@scope" )
const CallerSkipOffset = 2
CallerSkipOffset 调用栈便宜,用于输出日志位置
const (
// ContextLoggerKey 在 context 中存储 logger 的 key
ContextLoggerKey = "context.logger.key"
)
const (
// SampleCallerSkipOffset 通过内置 logger 输出日志, Caller + 1
SampleCallerSkipOffset = 1
)
Variables ¶
This section is empty.
Functions ¶
func DebugCtxWithFields ¶ added in v0.1.1
DebugCtxWithFields 通过 ctx 获取 logger, 以 debug 等级输出日志,并附加 fields 信息
func DebugF ¶ added in v0.1.1
func DebugF(format string, args ...interface{})
DebugF 通过内置 logger, 以 debug 等级格式化输出日志
func DebugWithFields ¶ added in v0.1.1
DebugWithFields 通过内置 logger, 以 debug 等级输出日志,并附加 fields 信息
func ErrorCtxWithFields ¶ added in v0.1.1
func ErrorWithFields ¶ added in v0.1.1
func FatalCtxWithFields ¶ added in v0.1.1
FatalCtxWithFields 通过 ctx 获取 logger,以 fatal 等级输出日志,并 附加 fields 信息
func FatalF ¶ added in v0.1.1
func FatalF(format string, args ...interface{})
FatalF 通过 ctx 获取 logger,以 fatal 等级格式化输出日志
func FatalWithFields ¶ added in v0.1.1
FatalWithFields 通过 内置 logger,以 fatal 等级输出日志,并 附加 fields 信息
func InfoCtxWithFields ¶ added in v0.1.1
func InfoWithFields ¶ added in v0.1.1
func PanicCtxWithFields ¶ added in v0.1.1
PanicCtxWithFields 通过 ctx 获取logger,以 panic 等级输出日志,并 附加 fields 信息
func PanicF ¶ added in v0.1.1
func PanicF(format string, args ...interface{})
PanicF 通过内置 logger,以 panic 等级格式化输出日志
func PanicWithFields ¶ added in v0.1.1
PanicWithFields 通过内置 logger,以 panic 等级输出日志,并 附加 fields 信息
func WarnCtxWithFields ¶ added in v0.1.1
func WarnWithFields ¶ added in v0.1.1
Types ¶
type Config ¶ added in v0.1.1
Config 类型别名,日志配置
func NewDefaultConfig ¶ added in v0.1.1
NewDefaultConfig 默认日志配置
type EncoderConfig ¶ added in v0.1.1
type EncoderConfig = zapcore.EncoderConfig
EncoderConfig 类型别名,棉麻配置
func NewDefaultEncoderConfig ¶ added in v0.1.1
func NewDefaultEncoderConfig() EncoderConfig
NewDefaultEncoderConfig 创建默认编码配置信息
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func ExtractLogger ¶
func NewLoggerWithConfig ¶ added in v0.1.1
NewLoggerWithConfig 通过自定义配置创建 logger
func (*Logger) AddCallerSkip ¶ added in v0.1.1
AddCallerSkip 创建新的 logger 并且增加 CallerSkip
func (*Logger) DebugWithField ¶
输出自定义 Key-Value 对 性能优于 WithField
func (*Logger) ErrorWithField ¶
func (*Logger) FatalWithField ¶
func (*Logger) InfoWithField ¶
func (*Logger) NewNamespace ¶
NewNamespace 派生 Logger 并创建一个 NameSpace
func (*Logger) PanicWithField ¶
func (*Logger) SetLevelHandler ¶
func (l *Logger) SetLevelHandler(w http.ResponseWriter, r *http.Request)
SetLevelHandler 设置 Web handler, 动态改变日志输出等级
func (*Logger) Sync ¶ added in v0.1.1
func (l *Logger) Sync()
Sync 刷新数据 flushing any buffered log entries, take care to call sync before exiting.
func (*Logger) WarnWithField ¶
func (*Logger) WithOutFile ¶
WithOutFile 派生一个Logger,将日志写入指定文件列表
func (*Logger) WithOutput ¶
WithOutput 派生一个Logger,附加 writer, 收集日志信息
func (*Logger) WithSampling ¶ added in v0.1.1
func (l *Logger) WithSampling(opts *SamplingOption) *Logger
type Options ¶
type Options struct {
// 日志文件名称
FileName string `json:"file_name" mapstructure:"file_name"`
// 日志备份路径
BackupPath string `json:"backup_path" mapstructure:"backup_path"`
// 日志文件最大字节数,单位为MB
MaxSize int `json:"max_size" mapstructure:"max_size"`
// 备份文件,日期后缀格式
SuffixFormat string `json:"suffix_format" mapstructure:"suffix_format"`
}
Options 日志自动备份配置
type RotateWriter ¶ added in v0.1.1
type RotateWriter struct {
// contains filtered or unexported fields
}
func (*RotateWriter) Close ¶ added in v0.1.1
func (r *RotateWriter) Close() error