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 StdErrLogger() *log.Logger
- func StdInfoLogger() *log.Logger
- 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
- type Field
- type InfoLogger
- type Level
- type Logger
- type Options
Constants ¶
View Source
const ( KeyRequestID = "REQUEST_ID" KeyEID = "E_ID" )
定义常见的日志字段。
Variables ¶
View Source
var ( // DebugLevel 日志通常是大量的,并且通常在生产中被禁用。 DebugLevel = zapcore.DebugLevel // InfoLevel 是默认的日志记录优先级。 InfoLevel = zapcore.InfoLevel // WarnLevel 日志比 Info 更重要,但不需要单独人工审查。 WarnLevel = zapcore.WarnLevel // ErrorLevel 日志是高优先级的。 如果应用程序运行顺利,则不应生成任何错误级别的日志。 ErrorLevel = zapcore.ErrorLevel // PanicLevel 记录一条消息,然后 Panic。 PanicLevel = zapcore.PanicLevel // FatalLevel 记录一条消息,然后调用 os.Exit(1)。 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 )
key-value 函数
Functions ¶
func Debugw ¶
func Debugw(msg string, keysAndValues ...interface{})
Debugw method output debug level log.
func Errorw ¶
func Errorw(msg string, keysAndValues ...interface{})
Errorw method output error level log.
func Fatalw ¶
func Fatalw(msg string, keysAndValues ...interface{})
Fatalw method output Fatalw level log.
func Infow ¶
func Infow(msg string, keysAndValues ...interface{})
Infow method output info level log.
func Panicf ¶
func Panicf(format string, v ...interface{})
Panicf method output panic level log and shutdown application.
func Panicw ¶
func Panicw(msg string, keysAndValues ...interface{})
Panicw method output panic level log.
func StdErrLogger ¶
StdErrLogger 返回标准库的 logger,该 logger 在 error level 写入提供的 zap logger。
func StdInfoLogger ¶
StdInfoLogger 返回标准库的 logger,该 logger 在 info level 写入提供的 zap logger。
Types ¶
type InfoLogger ¶
type InfoLogger interface { // Info 使用给定的键/值对作为上下文记录非错误消息。 // // msg 参数应该用于向日志行添加一些常量描述。 // 然后可以使用键/值对添加额外的变量信息。 // 键/值对应该交替使用字符串键和任意值。 Info(msg string, fields ...Field) Infof(format string, v ...interface{}) Infow(msg string, keysAndValues ...interface{}) // Enabled 测试是否启用了这个 InfoLogger。 // 例如,命令行标志可用于设置日志记录详细程度并禁用某些信息日志。 Enabled() bool }
InfoLogger 表示能够以特定的详细程度记录非错误消息。
type Logger ¶
type Logger interface { // InfoLogger 所有 Logger 都实现了 InfoLogger。 // 直接在 Logger 值上调用 InfoLogger 方法等效于在 V(0) InfoLogger 上调用它们。 // 例如,logger.Info() 产生与 logger.V(0).Info 相同的结果。 InfoLogger Debug(msg string, fields ...Field) Debugf(format string, v ...interface{}) Debugw(msg string, keysAndValues ...interface{}) Warn(msg string, fields ...Field) Warnf(format string, v ...interface{}) Warnw(msg string, keysAndValues ...interface{}) Error(msg string, fields ...Field) Errorf(format string, v ...interface{}) Errorw(msg string, keysAndValues ...interface{}) Panic(msg string, fields ...Field) Panicf(format string, v ...interface{}) Panicw(msg string, keysAndValues ...interface{}) Fatal(msg string, fields ...Field) Fatalf(format string, v ...interface{}) Fatalw(msg string, keysAndValues ...interface{}) // V 返回特定详细级别的 InfoLogger 值。 // 一个更高的详细级别意味着日志消息不太重要。 // 传递小于零的日志级别是违法的。 V(level int) InfoLogger Write(p []byte) (n int, err error) // WithValues 向 logger 添加一些上下文的键值对。 // 有关键/值对如何工作的文档,请参阅 Info。 WithValues(keysAndValues ...interface{}) Logger // WithName 向记录器的名称添加一个新元素。 // 使用 WithName 的连续调用继续向记录器的名称附加后缀。 // 强烈建议名称段仅包含字母、数字和连字符。 WithName(name string) Logger // WithContext 返回设置日志值的上下文副本。 WithContext(ctx context.Context) context.Context // Flush 调用底层 Core 的 Sync 方法,刷新所有缓冲的日志条目。 // 应用程序应注意在退出前调用 Sync。 Flush() }
Logger 记录日志消息。
func WithValues ¶
func WithValues(keysAndValues ...interface{}) Logger
WithValues 创建一个 child logger 并向其添加 Zap 字段。
type Options ¶
type Options struct { OutputPaths []string `json:"output-paths" mapstructure:"output-paths"` ErrorOutputPaths []string `json:"error-output-paths" mapstructure:"error-output-paths"` Level string `json:"level" mapstructure:"level"` Format string `json:"format" mapstructure:"format"` DisableCaller bool `json:"disable-caller" mapstructure:"disable-caller"` DisableStacktrace bool `json:"disable-stacktrace" mapstructure:"disable-stacktrace"` EnableColor bool `json:"enable-color" mapstructure:"enable-color"` EncodeFullCaller bool `json:"enable-full-caller" mapstructure:"enable-full-caller"` Development bool `json:"development" mapstructure:"development"` Name string `json:"name" mapstructure:"name"` }
Options 日志相关的配置项。
Click to show internal directories.
Click to hide internal directories.