Documentation ¶
Overview ¶
Package log 日志操作工具
Index ¶
- Constants
- Variables
- func Binary(key string, val []byte) zapcore.Field
- func Bool(key string, val bool) zapcore.Field
- func ByteString(key string, val []byte) zapcore.Field
- func Complex128(key string, val complex128) zapcore.Field
- func Complex64(key string, val complex64) zapcore.Field
- func Duration(key string, val time.Duration) zapcore.Field
- func Error(err error) zapcore.Field
- func Float32(key string, val float32) zapcore.Field
- func Float64(key string, val float64) zapcore.Field
- func Int(key string, val int) zapcore.Field
- func Int16(key string, val int16) zapcore.Field
- func Int32(key string, val int32) zapcore.Field
- func Int64(key string, val int64) zapcore.Field
- func Int8(key string, val int8) zapcore.Field
- func NamedError(key string, err error) zapcore.Field
- func Namespace(key string) zapcore.Field
- func Object(key string, val zapcore.ObjectMarshaler) zapcore.Field
- func Reflect(key string, val interface{}) zapcore.Field
- func Skip() zapcore.Field
- func String(key string, val string) zapcore.Field
- func Stringer(key string, val fmt.Stringer) zapcore.Field
- func Time(key string, val time.Time) zapcore.Field
- func Uint(key string, val uint) zapcore.Field
- func Uint16(key string, val uint16) zapcore.Field
- func Uint32(key string, val uint32) zapcore.Field
- func Uint64(key string, val uint64) zapcore.Field
- func Uint8(key string, val uint8) zapcore.Field
- func Uintptr(key string, val uintptr) zapcore.Field
- type Config
- type Level
- type Logger
- func (log *Logger) Conf(config *Config)
- func (log *Logger) Init(logPath, serviceName string, config *Config, dev bool)
- func (log *Logger) New(filePath string, serviceName string) *zap.Logger
- func (log *Logger) New1(name string, serviceName string) *zap.Logger
- func (log *Logger) NewCustom(filePath string, level Level, maxSize int, maxBackups int, maxAge int, ...) *zap.Logger
- func (log *Logger) Self(serviceName string)
Constants ¶
const ( // ReadFileForCACertFail 根据指定路径读取 CA 证书文件失败 ReadFileForCACertFail = iota )
Variables ¶
var ( // Log 日志全局对象 Log Logger // Common 通用包日志对象 Common, _ = zap.NewDevelopment() // Discovery 发现服务包日志对象 Discovery, _ = zap.NewDevelopment() // Examples 案例日志对象 Examples, _ = zap.NewDevelopment() // Rivet 框架日志对象 Rivet, _ = zap.NewDevelopment() // Server 关联接口服务日志对象 Server, _ = zap.NewDevelopment() // Bow 网关日志对象 Bow, _ = zap.NewDevelopment() // Shunt 负载均衡日志对象 Shunt, _ = zap.NewDevelopment() // Trans 请求处理日志对象 Trans, _ = zap.NewDevelopment() // Scheduled 定时任务日志对象 Scheduled, _ = zap.NewDevelopment() // Self 当前使用该框架服务日志对象 Self, _ = zap.NewDevelopment() )
Functions ¶
func Binary ¶
Binary constructs a field that carries an opaque binary blob.
Binary data is serialized in an encoding-appropriate format. For example, zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text, use ByteString.
func ByteString ¶
ByteString constructs a field that carries UTF-8 encoded text as a []byte. To log opaque binary blobs (which aren't necessarily valid UTF-8), use Binary.
func Complex128 ¶
func Complex128(key string, val complex128) zapcore.Field
Complex128 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex128 to interface{}).
func Complex64 ¶
Complex64 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex64 to interface{}).
func Duration ¶
Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.
func Float32 ¶
Float32 constructs a field that carries a float32. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.
func Float64 ¶
Float64 constructs a field that carries a float64. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.
func NamedError ¶
NamedError constructs a field that lazily stores err.Error() under the provided key. Errors which also implement fmt.Formatter (like those produced by github.com/pkg/errors) will also have their verbose representation stored under key+"Verbose". If passed a nil error, the field is a no-op.
For the common case in which the key is simply "error", the Error function is shorter and less repetitive.
func Namespace ¶
Namespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.
This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.
func Object ¶
func Object(key string, val zapcore.ObjectMarshaler) zapcore.Field
Object constructs a field with the given key and ObjectMarshaler. It provides a flexible, but still type-safe and efficient, way to add map- or struct-like user-defined types to the logging context. The struct's MarshalLogObject method is called lazily.
func Reflect ¶
Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.
If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.
func Skip ¶
Skip constructs a no-op field, which is often useful when handling invalid inputs in other zapcore.Field constructors.
func Stringer ¶
Stringer constructs a field with the given key and the output of the value's String method. The Stringer's String method is called lazily.
func Time ¶
Time constructs a zapcore.Field with the given key and value. The encoder controls how the time is serialized.
Types ¶
type Config ¶
type Config struct { Level Level // 日志输出级别 MaxSize int // 每个日志文件保存的最大尺寸 单位:M MaxBackups int // 日志文件最多保存多少个备份 MaxAge int // 文件最多保存多少天 Compress bool // 是否压缩 }
Config 日志配置对象
type Level ¶
type Level int8
A Level is a logging priority. Higher levels are more important.
const ( // DebugLevel logs are typically voluminous, and are usually disabled in // production. DebugLevel Level = iota - 1 // InfoLevel is the default logging priority. InfoLevel // WarnLevel logs are more important than Info, but don't need individual // human review. WarnLevel // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. ErrorLevel // DPanicLevel logs are particularly important errors. In development the // logger panics after writing the message. DPanicLevel // PanicLevel logs a message, then panics. PanicLevel // FatalLevel logs a message, then calls os.Exit(1). FatalLevel )
type Logger ¶
type Logger struct {
Config *Config
}
Logger 日志入口对象