Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(msg string, fields ...Field)
- func Debugf(format string, v ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func Error(msg string, fields ...Field)
- func Errorf(format string, v ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(msg string, fields ...Field)
- func Fatalf(format string, v ...interface{})
- func Fatalw(msg string, keysAndValues ...interface{})
- func Flush()
- func Info(msg string, fields ...Field)
- func Infof(format string, v ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func Init(opts *Options)
- func L(ctx context.Context) *zapLogger
- func New(opts *Options) *zapLogger
- func Panic(msg string, fields ...Field)
- func Panicf(format string, v ...interface{})
- func Panicw(msg string, keysAndValues ...interface{})
- func SugaredLogger() *zap.SugaredLogger
- func Warn(msg string, fields ...Field)
- func Warnf(format string, v ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- func WithContext(ctx context.Context) context.Context
- func ZapLogger() *zap.Logger
- type Field
- type Level
- type Logger
- type Options
Constants ¶
View Source
const ( KeyRequestID string = "requestID" KeyUsername string = "username" )
Variables ¶
View Source
var ( DebugLevel = zapcore.DebugLevel InfoLevel = zapcore.InfoLevel WarnLevel = zapcore.WarnLevel ErrorLevel = zapcore.ErrorLevel PanicLevel = zapcore.PanicLevel FatalLevel = zapcore.FatalLevel )
View Source
var ( Any = zap.Any Array = zap.Array Object = zap.Object Binary = zap.Binary Bool = zap.Bool Bools = zap.Bools ByteString = zap.ByteString ByteStrings = zap.ByteStrings Complex64 = zap.Complex64 Complex64s = zap.Complex64s Complex128 = zap.Complex128 Complex128s = zap.Complex128s Duration = zap.Duration Durations = zap.Durations Err = zap.Error Errors = zap.Errors Float32 = zap.Float32 Float32s = zap.Float32s Float64 = zap.Float64 Float64s = zap.Float64s Int = zap.Int Ints = zap.Ints Int8 = zap.Int8 Int8s = zap.Int8s Int16 = zap.Int16 Int16s = zap.Int16s Int32 = zap.Int32 Int32s = zap.Int32s Int64 = zap.Int64 Int64s = zap.Int64s Namespace = zap.Namespace Reflect = zap.Reflect Stack = zap.Stack String = zap.String Stringer = zap.Stringer Strings = zap.Strings Time = zap.Time Times = zap.Times Uint = zap.Uint Uints = zap.Uints Uint8 = zap.Uint8 Uint8s = zap.Uint8s Uint16 = zap.Uint16 Uint16s = zap.Uint16s Uint32 = zap.Uint32 Uint32s = zap.Uint32s Uint64 = zap.Uint64 Uint64s = zap.Uint64s Uintptr = zap.Uintptr Uintptrs = zap.Uintptrs )
Alias for zap type functions.
Functions ¶
func SugaredLogger ¶
func SugaredLogger() *zap.SugaredLogger
SugaredLogger returns global sugared logger.
Types ¶
type Logger ¶
type Logger interface { // Debug 日志 Debug(msg string, fields ...Field) Debugf(format string, v ...interface{}) Debugw(msg string, keysAndValues ...interface{}) // Info 日志 Info(msg string, fields ...Field) Infof(format string, v ...interface{}) Infow(msg string, keysAndValues ...interface{}) // Warn 日志 Warn(msg string, fields ...Field) Warnf(format string, v ...interface{}) Warnw(msg string, keysAndValues ...interface{}) // Error 日志 Error(msg string, fields ...Field) Errorf(format string, v ...interface{}) Errorw(msg string, keysAndValues ...interface{}) // Panic 日志 Panic(msg string, fields ...Field) Panicf(format string, v ...interface{}) Panicw(msg string, keysAndValues ...interface{}) // Fatal 日志 Fatal(msg string, fields ...Field) Fatalf(format string, v ...interface{}) Fatalw(msg string, keysAndValues ...interface{}) // WithValues 向 logger 添加一些上下文的 key-value 对。 WithValues(keysAndValues ...interface{}) Logger // WithName 向 logger 的名称添加一个新元素,建议名称段仅包含字母、数字和连字符 WithName(name string) Logger // WithContext 返回设置了日志值的 context 副本 WithContext(ctx context.Context) context.Context // Flush 调用底层 Core 的 Sync 方法,刷新所有缓冲的日志条目,应用程序应注意在退出之前调用 Sync Flush() }
Logger 接口定义记录日志的能力
func FromContext ¶
FromContext returns the value of the log key on the ctx.
func WithValues ¶
func WithValues(keysAndValues ...interface{}) Logger
type Options ¶
type Options struct { // Logger 的名字 Name string `json:"name" mapstructure:"name"` // 是否是开发模式。如果是开发模式,会对 WarnLevel 以上进行堆栈跟踪; // 非开发模式,会对 PanicLevel 以上进行堆栈跟踪。 Development bool `json:"development" mapstructure:"development"` // 日志级别,优先级从低到高依次为:Debug, Info, Warn, Error, Dpanic, Panic, Fatal Level string `json:"level" mapstructure:"level"` // 是否开启颜色输出,true,是;false,否 EnableColor bool `json:"enable-color" mapstructure:"enable-color"` // 是否开启 caller,如果开启会在日志中显示调用日志所在的文件、函数和行号 DisableCaller bool `json:"disable-caller" mapstructure:"disable-caller"` // 是否在 WarnLevel(开发模式) 或 PanicLevel(非开发模式) 及以上级别禁止打印堆栈信息 DisableStacktrace bool `json:"disable-stacktrace" mapstructure:"disable-stacktrace"` // 支持的日志输出格式,支持 Console 和 JSON 两种 Format string `json:"format" mapstructure:"format"` // 支持输出到多个输出,用逗号分开。支持输出到标准输出(stdout)和文件 OutputPaths []string `json:"output-paths" mapstructure:"output-paths"` // zap 内部 (非业务) 错误日志输出路径,多个输出,用逗号分开 ErrorOutputPaths []string `json:"error-output-paths" mapstructure:"error-output-paths"` // MaxSize 是日志文件轮转之前的最大大小(MB)。默认为 100MB。 MaxSize int `json:"maxsize" mapstructure:"maxsize"` // MaxAge 是根据文件名中编码的时间戳保留旧日志文件的最大天数。 MaxAge int `json:"maxage" mapstructure:"maxage"` // MaxBackups 是要保留的旧日志文件的最大数量。 MaxBackups int `json:"maxbackups" mapstructure:"maxbackups"` // Compress 确定是否应使用 gzip 压缩轮转的日志文件。 Compress bool `json:"compress" mapstructure:"compress"` // Port 用于指定动态修改日志输出级别端口,默认为 0 (不开启)。 Port int `json:"port" mapstructure:"port"` }
Options 包含所有日志相关的配置项
func NewOptions ¶
func NewOptions() *Options
Click to show internal directories.
Click to hide internal directories.