Documentation ¶
Index ¶
- Constants
- Variables
- 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 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 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 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 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 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 WithLogger(ctx context.Context, logger *Logger) context.Context
- type Config
- type EncoderConfig
- type Fields
- type Key
- 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
- func (l *Logger) Write(msg []byte) (int, error)
- 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 (
// SampleCallerSkipOffset 通过内置 logger 输出日志, Caller + 1
SampleCallerSkipOffset = 1
)
Variables ¶
var ( // Debug 内置 logger 以 debug 等级输出日志 Debug = simpleLogger.Debug // DebugF 通过内置 logger, 以 debug 等级格式化输出日志 DebugF = simpleLogger.DebugF // DebugWithFields 通过内置 logger, 以 debug 等级输出日志,并附加 fields 信息 DebugWithFields = simpleLogger.DebugWithField // Info 内置 logger 以 info 等级输出日志 Info = simpleLogger.Info // InfoF 通过内置 logger, 以 info 等级格式化输出日志 InfoF = simpleLogger.InfoF // InfoWithFields 通过内置 logger, 以 info 等级输出日志,并附加 fields 信息 InfoWithFields = simpleLogger.InfoWithField // Warn 内置 logger 以 warn 等级输出日志 Warn = simpleLogger.Warn // WarnF 通过内置 logger, 以 warn 等级格式化输出日志 WarnF = simpleLogger.WarnF // WarnWithFields 通过内置 logger, 以 warn 等级输出日志,并附加 fields 信息 WarnWithFields = simpleLogger.WarnWithField // Error 内置 logger 以 error 等级输出日志 Error = simpleLogger.Error // ErrorF 通过内置 logger, 以 error 等级格式化输出日志 ErrorF = simpleLogger.ErrorF // ErrorWithFields 通过内置 logger, 以 error 等级输出日志,并附加 fields 信息 ErrorWithFields = simpleLogger.ErrorWithField )
Functions ¶
func DebugCtxWithFields ¶
DebugCtxWithFields 通过 ctx 获取 logger, 以 debug 等级输出日志,并附加 fields 信息
func ErrorCtxWithFields ¶
func FatalCtxWithFields ¶
FatalCtxWithFields 通过 ctx 获取 logger,以 fatal 等级输出日志,并 附加 fields 信息
func FatalF ¶
func FatalF(format string, args ...interface{})
FatalF 通过 ctx 获取 logger,以 fatal 等级格式化输出日志
func FatalWithFields ¶
FatalWithFields 通过 内置 logger,以 fatal 等级输出日志,并 附加 fields 信息
func PanicCtxWithFields ¶
PanicCtxWithFields 通过 ctx 获取logger,以 panic 等级输出日志,并 附加 fields 信息
func PanicWithFields ¶
PanicWithFields 通过内置 logger,以 panic 等级输出日志,并 附加 fields 信息
Types ¶
type EncoderConfig ¶
type EncoderConfig = zapcore.EncoderConfig
EncoderConfig 类型别名,棉麻配置
func NewDefaultEncoderConfig ¶
func NewDefaultEncoderConfig() EncoderConfig
NewDefaultEncoderConfig 创建默认编码配置信息
type Key ¶
type Key string
Key 内部key类型
const ( // ContextLoggerKey 在 context 中存储 logger 的 key ContextLoggerKey Key = "context.logger.key" )
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewLoggerWithConfig ¶
NewLoggerWithConfig 通过自定义配置创建 logger
func (*Logger) AddCallerSkip ¶
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 ¶
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 ¶
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 ¶
type RotateWriter struct {
// contains filtered or unexported fields
}
func (*RotateWriter) Close ¶
func (r *RotateWriter) Close() error