Documentation ¶
Index ¶
- Constants
- Variables
- func Init(options ...ConfigOption)
- func ResetDefault(l *Logger)
- func SetDefaultConf(options ...ConfigOption)
- type Conf
- type ConfigOption
- func WithCtxField(fieldsKey ...string) ConfigOption
- func WithDistinguish(isDistinguish bool) ConfigOption
- func WithEncoderJSON(isJSONEncoder bool) ConfigOption
- func WithFields(fields ...zapcore.Field) ConfigOption
- func WithLevel(level string) ConfigOption
- func WithLogInConsole(isLogInConsole bool) ConfigOption
- func WithPath(path string) ConfigOption
- func WithPreName(pre string) ConfigOption
- func WithTimeFormat(format string) ConfigOption
- type Logger
- func (l *Logger) DPanic(msg string, fields ...zapcore.Field)
- func (l *Logger) DPanicWithCtx(c context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) DPanicf(template string, args ...interface{})
- func (l *Logger) DPanicfWithCtx(c context.Context, template string, args ...interface{})
- func (l *Logger) DPanicw(msg string, keysAndValues ...interface{})
- func (l *Logger) DPanicwWithCtx(c context.Context, msg string, keysAndValues ...interface{})
- func (l *Logger) Debug(msg string, fields ...zapcore.Field)
- func (l *Logger) DebugWithCtx(c context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Debugf(template string, args ...interface{})
- func (l *Logger) DebugfWithCtx(c context.Context, template string, args ...interface{})
- func (l *Logger) Debugw(msg string, keysAndValues ...interface{})
- func (l *Logger) DebugwWithCtx(c context.Context, msg string, keysAndValues ...interface{})
- func (l *Logger) Error(msg string, fields ...zapcore.Field)
- func (l *Logger) ErrorWithCtx(c context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Errorf(template string, args ...interface{})
- func (l *Logger) ErrorfWithCtx(c context.Context, template string, args ...interface{})
- func (l *Logger) Errorw(msg string, keysAndValues ...interface{})
- func (l *Logger) ErrorwWithCtx(c context.Context, msg string, keysAndValues ...interface{})
- func (l *Logger) Fatal(msg string, fields ...zapcore.Field)
- func (l *Logger) FatalWithCtx(c context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Fatalf(template string, args ...interface{})
- func (l *Logger) FatalfWithCtx(c context.Context, template string, args ...interface{})
- func (l *Logger) Fatalw(msg string, keysAndValues ...interface{})
- func (l *Logger) FatalwWithCtx(c context.Context, msg string, keysAndValues ...interface{})
- func (l *Logger) Info(msg string, fields ...zapcore.Field)
- func (l *Logger) InfoWithCtx(c context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Infof(template string, args ...interface{})
- func (l *Logger) InfofWithCtx(c context.Context, template string, args ...interface{})
- func (l *Logger) Infow(msg string, keysAndValues ...interface{})
- func (l *Logger) InfowWithCtx(c context.Context, msg string, keysAndValues ...interface{})
- func (l *Logger) Log() *zap.Logger
- func (l *Logger) Name() string
- func (l *Logger) Panic(msg string, fields ...zapcore.Field)
- func (l *Logger) PanicWithCtx(c context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Panicf(template string, args ...interface{})
- func (l *Logger) PanicfWithCtx(c context.Context, template string, args ...interface{})
- func (l *Logger) Panicw(msg string, keysAndValues ...interface{})
- func (l *Logger) PanicwWithCtx(c context.Context, msg string, keysAndValues ...interface{})
- func (l *Logger) Printf(template string, args ...interface{})
- func (l *Logger) Sugar() *zap.SugaredLogger
- func (l *Logger) Sync() error
- func (l *Logger) Warn(msg string, fields ...zapcore.Field)
- func (l *Logger) WarnWithCtx(c context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Warnf(template string, args ...interface{})
- func (l *Logger) WarnfWithCtx(c context.Context, template string, args ...interface{})
- func (l *Logger) Warnw(msg string, keysAndValues ...interface{})
- func (l *Logger) WarnwWithCtx(c context.Context, msg string, keysAndValues ...interface{})
Constants ¶
const ( DebugLevel = "debug" InfoLevel = "info" WarnLevel = "warn" ErrorLevel = "error" )
Variables ¶
var ( Sugar = std.Sugar Debug = std.Debug Info = std.Info Warn = std.Warn Error = std.Error DPanic = std.DPanic Panic = std.Panic Fatal = std.Fatal Debugf = std.Debugf Infof = std.Infof Warnf = std.Warnf Errorf = std.Errorf DPanicf = std.DPanicf Panicf = std.Panicf Fatalf = std.Fatalf Debugw = std.Debugw Infow = std.Infow Warnw = std.Warnw Errorw = std.Errorw DPanicw = std.DPanicw Panicw = std.Panicw Fatalw = std.Fatalw DebugWithCtx = std.DebugWithCtx InfoWithCtx = std.InfoWithCtx WarnWithCtx = std.WarnWithCtx ErrorWithCtx = std.ErrorWithCtx DPanicWithCtx = std.DPanicWithCtx PanicWithCtx = std.PanicWithCtx FatalWithCtx = std.FatalWithCtx DebugfWithCtx = std.DebugfWithCtx InfofWithCtx = std.InfofWithCtx WarnfWithCtx = std.WarnfWithCtx ErrorfWithCtx = std.ErrorfWithCtx DPanicfWithCtx = std.DPanicfWithCtx PanicfWithCtx = std.PanicfWithCtx FatalfWithCtx = std.FatalfWithCtx DebugwWithCtx = std.DebugwWithCtx InfowWithCtx = std.InfowWithCtx WarnwWithCtx = std.WarnwWithCtx ErrorwWithCtx = std.ErrorwWithCtx DPanicwWithCtx = std.DPanicwWithCtx PanicwWithCtx = std.PanicwWithCtx FatalwWithCtx = std.FatalwWithCtx )
Functions ¶
func Init ¶
func Init(options ...ConfigOption)
Types ¶
type Conf ¶
type Conf struct { Name string Path string // 日志路径,默认为 . IsDistinguish bool // 区分正常日志和错误日志 LowLevel zapcore.Level // 最低打印级别,默认为 debug LogInConsole bool // 是否打印到控制台,默认为 false Fields []zapcore.Field // 该日志都加的字段,默认为空 IsJSONEncode bool // 是否为json格式日志,默认为 true TimeFormat string // 时间格式,默认为 2006-01-02T15:04:05Z07:00 PreName string // 日志前缀 CtxFields []string // 打印上下文字段 }
type ConfigOption ¶
type ConfigOption func(conf *Conf)
func WithCtxField ¶
func WithCtxField(fieldsKey ...string) ConfigOption
添加需要打印的上下文字段, 新建的日志将会是新配置,已经建立的日志配置不变
func WithDistinguish ¶
func WithDistinguish(isDistinguish bool) ConfigOption
WithDistinguish 是否区分日志级别,<=info和>=err分开记录 @param isDistinguish @return ConfigOption
func WithEncoderJSON ¶
func WithEncoderJSON(isJSONEncoder bool) ConfigOption
WithEncoderJSON 是否设置为json格式日志 @param isJSONEncoder @return ConfigOption
func WithFields ¶
func WithFields(fields ...zapcore.Field) ConfigOption
WithFields 添加全局日志的新字段, 新建的日志将会是新配置,已经建立的日志配置不变 @param field 日志字段
func WithLevel ¶
func WithLevel(level string) ConfigOption
WithLevel 设置服务记录的最低日志级别 修改后,新建的日志将会是新配置,已经建立的日志配置不变 @param l 日志级别(debug、info、warn、error)
func WithLogInConsole ¶
func WithLogInConsole(isLogInConsole bool) ConfigOption
WithLogInConsole 是否输出到控制台 修改后,新建的日志将会是新配置,已经建立的日志配置不变 @param isLogInConsole
func WithPath ¶
func WithPath(path string) ConfigOption
WithPath 设置日志路径, 修改后,新建的日志将会是新配置,已经建立的日志配置不变 @param path 路径
func WithPreName ¶
func WithPreName(pre string) ConfigOption
WithPreName 设置日志前缀 @param pre 前缀 @return ConfigOption
func WithTimeFormat ¶
func WithTimeFormat(format string) ConfigOption
WithTimeFormat 设置时间格式 @param format 时间格式 @return ConfigOption
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func New ¶
func New(name string, options ...ConfigOption) *Logger
New 创建新日志文件句柄,使用默认配置 @param name 日志名 @param options 日志配置,将覆盖默认配置 @return *Logger
func (*Logger) DPanic ¶
DPanic logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.
func (*Logger) DPanicWithCtx ¶
DPanic logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.
func (*Logger) DPanicf ¶
DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)
func (*Logger) DPanicfWithCtx ¶
DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)
func (*Logger) DPanicw ¶
DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.
func (*Logger) DPanicwWithCtx ¶
DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.
func (*Logger) Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) DebugWithCtx ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) DebugfWithCtx ¶
Debugf uses fmt.Sprintf to log a templated message.
func (*Logger) Debugw ¶
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).Debug(msg)
func (*Logger) DebugwWithCtx ¶
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).Debug(msg)
func (*Logger) Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) ErrorWithCtx ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) ErrorfWithCtx ¶
Errorf uses fmt.Sprintf to log a templated message.
func (*Logger) Errorw ¶
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Logger) ErrorwWithCtx ¶
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Logger) Fatal ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func (*Logger) FatalWithCtx ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func (*Logger) FatalfWithCtx ¶
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func (*Logger) Fatalw ¶
Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.
func (*Logger) FatalwWithCtx ¶
Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.
func (*Logger) Info ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) InfoWithCtx ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) InfofWithCtx ¶
Infof uses fmt.Sprintf to log a templated message.
func (*Logger) Infow ¶
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Logger) InfowWithCtx ¶
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Logger) Panic ¶
Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then panics, even if logging at PanicLevel is disabled.
func (*Logger) PanicWithCtx ¶
Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then panics, even if logging at PanicLevel is disabled.
func (*Logger) PanicfWithCtx ¶
Panicf uses fmt.Sprintf to log a templated message, then panics.
func (*Logger) Panicw ¶
Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.
func (*Logger) PanicwWithCtx ¶
Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.
func (*Logger) Sugar ¶
func (l *Logger) Sugar() *zap.SugaredLogger
func (*Logger) Warn ¶
Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) WarnWithCtx ¶
Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) WarnfWithCtx ¶
Warnf uses fmt.Sprintf to log a templated message.