Documentation ¶
Index ¶
- Constants
- Variables
- func CallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- func DPanic(msg string, fields ...zap.Field)
- func DPanicf(format string, v ...interface{})
- func DPanicln(v ...interface{})
- func Debug(msg string, fields ...zap.Field)
- func Debugf(format string, v ...interface{})
- func Debugln(v ...interface{})
- func DurationEncoder(d time.Duration, enc zapcore.PrimitiveArrayEncoder)
- func Error(msg string, fields ...zap.Field)
- func Errorf(format string, v ...interface{})
- func Errorln(v ...interface{})
- func Fatal(msg string, fields ...zap.Field)
- func Fatalf(format string, v ...interface{})
- func Fataln(v ...interface{})
- func GenTraceId(ctx context.Context) (traceId string)
- func GetIntranetIpv4() (ip string, err error)
- func GetIp() string
- func Info(msg string, fields ...zap.Field)
- func Infof(format string, v ...interface{})
- func Infoln(v ...interface{})
- func LevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func NewFCLogEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder
- func NewSpanId(ctx context.Context) string
- func Panic(msg string, fields ...zap.Field)
- func Panicf(format string, v ...interface{})
- func Panicln(v ...interface{})
- func Print(msg string, fields ...zap.Field)
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func SetConfig(c Config, logDir string)
- func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Warn(msg string, fields ...zap.Field)
- func Warnf(format string, v ...interface{})
- func Warnln(v ...interface{})
- type Config
- type FCLogEncoder
- func (enc *FCLogEncoder) AddArray(key string, arr zapcore.ArrayMarshaler) error
- func (enc *FCLogEncoder) AddBinary(key string, val []byte)
- func (enc *FCLogEncoder) AddBool(key string, val bool)
- func (enc *FCLogEncoder) AddByteString(key string, val []byte)
- func (enc *FCLogEncoder) AddComplex128(key string, val complex128)
- func (enc *FCLogEncoder) AddComplex64(k string, v complex64)
- func (enc *FCLogEncoder) AddDuration(key string, val time.Duration)
- func (enc *FCLogEncoder) AddFloat32(k string, v float32)
- func (enc *FCLogEncoder) AddFloat64(key string, val float64)
- func (enc *FCLogEncoder) AddInt(k string, v int)
- func (enc *FCLogEncoder) AddInt16(k string, v int16)
- func (enc *FCLogEncoder) AddInt32(k string, v int32)
- func (enc *FCLogEncoder) AddInt64(key string, val int64)
- func (enc *FCLogEncoder) AddInt8(k string, v int8)
- func (enc *FCLogEncoder) AddObject(key string, obj zapcore.ObjectMarshaler) error
- func (enc *FCLogEncoder) AddReflected(key string, obj interface{}) error
- func (enc *FCLogEncoder) AddString(key, val string)
- func (enc *FCLogEncoder) AddTime(key string, val time.Time)
- func (enc *FCLogEncoder) AddUint(k string, v uint)
- func (enc *FCLogEncoder) AddUint16(k string, v uint16)
- func (enc *FCLogEncoder) AddUint32(k string, v uint32)
- func (enc *FCLogEncoder) AddUint64(key string, val uint64)
- func (enc *FCLogEncoder) AddUint8(k string, v uint8)
- func (enc *FCLogEncoder) AddUintptr(k string, v uintptr)
- func (enc *FCLogEncoder) AppendArray(arr zapcore.ArrayMarshaler) error
- func (enc *FCLogEncoder) AppendBool(val bool)
- func (enc *FCLogEncoder) AppendByteString(val []byte)
- func (enc *FCLogEncoder) AppendComplex128(val complex128)
- func (enc *FCLogEncoder) AppendComplex64(v complex64)
- func (enc *FCLogEncoder) AppendDuration(val time.Duration)
- func (enc *FCLogEncoder) AppendFloat32(v float32)
- func (enc *FCLogEncoder) AppendFloat64(v float64)
- func (enc *FCLogEncoder) AppendInt(v int)
- func (enc *FCLogEncoder) AppendInt16(v int16)
- func (enc *FCLogEncoder) AppendInt32(v int32)
- func (enc *FCLogEncoder) AppendInt64(val int64)
- func (enc *FCLogEncoder) AppendInt8(v int8)
- func (enc *FCLogEncoder) AppendObject(obj zapcore.ObjectMarshaler) error
- func (enc *FCLogEncoder) AppendReflected(val interface{}) error
- func (enc *FCLogEncoder) AppendString(val string)
- func (enc *FCLogEncoder) AppendTime(val time.Time)
- func (enc *FCLogEncoder) AppendUint(v uint)
- func (enc *FCLogEncoder) AppendUint16(v uint16)
- func (enc *FCLogEncoder) AppendUint32(v uint32)
- func (enc *FCLogEncoder) AppendUint64(val uint64)
- func (enc *FCLogEncoder) AppendUint8(v uint8)
- func (enc *FCLogEncoder) AppendUintptr(v uintptr)
- func (enc *FCLogEncoder) Clone() zapcore.Encoder
- func (enc *FCLogEncoder) EncodeEntry(ent zapcore.Entry, fields []zap.Field) (*buffer.Buffer, error)
- func (enc *FCLogEncoder) OpenNamespace(key string)
- type Fields
- type HintContent
- type HintSampling
- type Logger
- func (l *Logger) Clone() *Logger
- func (l *Logger) ClonePure() *Logger
- func (l *Logger) DPanic(msg string, fields ...zap.Field)
- func (l *Logger) DPanicf(format string, v ...interface{})
- func (l *Logger) DPanicln(v ...interface{})
- func (l *Logger) Debug(msg string, fields ...zap.Field)
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) Error(msg string, fields ...zap.Field)
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Errorln(v ...interface{})
- func (l *Logger) Fatal(msg string, fields ...zap.Field)
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fataln(v ...interface{})
- func (l *Logger) GetTrace(ctx context.Context) *Trace
- func (l *Logger) Info(msg string, fields ...zap.Field)
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoln(v ...interface{})
- func (logger *Logger) LogWithError(err error, fieldss ...Fields)
- func (l *Logger) Named(s string) *Logger
- func (l *Logger) Panic(msg string, fields ...zap.Field)
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Panicln(v ...interface{})
- func (l *Logger) ParseTrace(req *http.Request)
- func (l *Logger) Print(msg string, fields ...zap.Field)
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) ResetTrace(ctx context.Context) *Trace
- func (l *Logger) SetTraceToWriter(ctx context.Context, rw http.ResponseWriter)
- func (l *Logger) Warn(msg string, fields ...zap.Field)
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warnln(v ...interface{})
- func (l *Logger) With(fields ...zap.Field) *Logger
- func (l *Logger) WithBF(ctx context.Context) *Logger
- type RotateConfig
- type RotateWriter
- func (l *RotateWriter) Close() error
- func (l *RotateWriter) OpenExistingOrNew() error
- func (l *RotateWriter) PrefixAndExt() (prefix, ext string)
- func (l *RotateWriter) Rotate() error
- func (l *RotateWriter) TimeFromName(filename, prefix, ext string, compress bool) (time.Time, error)
- func (l *RotateWriter) Write(p []byte) (n int, err error)
- type Trace
- type Writer
Constants ¶
const ( LOGTAG_REQUEST_IN = "_request_in" LOGTAG_REQUEST_OUT = "_request_out" LOGTAG_MYSQL_SUCCESS = "_mysql_succ" LOGTAG_MYSQL_FAILURE = "_mysql_fail" LOGTAG_MONGO_SUCCESS = "_mongo_succ" LOGTAG_MONGO_FAILURE = "_mongo_fail" LOGTAG_REDIS_SUCCESS = "_redis_succ" LOGTAG_REDIS_FAILURE = "_redis_fail" LOGTAG_THRIFT_SUCCESS = "_thrift_succ" LOGTAG_THRIFT_FAILURE = "_thrift_fail" LOGTAG_HTTP_SUCCESS = "_http_succ" LOGTAG_HTTP_FAILURE = "_http_fail" LOGTAG_PROXY_SUCCESS = "_proxy_succ" LOGTAG_PROXY_FAILURE = "_proxy_fail" LOGTAG_ENGINE_OK = "_engine_succ" LOGTAG_ENGINE_ERR = "_engine_fail" LOGTAG_ELASTIC_SUCCESS = "_elastic_succ" LOGTAG_ELASTIC_FAILURE = "_elastic_fail" LOGTAG_ACTIVEMQ_SUCCESS = "_activemq_succ" LOGTAG_ACTIVEMQ_FAILURE = "_avtivemq_fail" )
const ( LOGKEY_BEGIN = "__TIME__" LOGKEY_TAG = "tag" )
const (
LOG_OK = "ok"
)
const (
LOG_TIME_FORMAT = "[2006-01-02 15:04:05.000-0700]"
)
const (
X_REQUEST_HEADER_RID = "X-Request-Id"
)
Variables ¶
var ErrMissingLevel = errors.New("missing level")
var TagSuccessFailureRelation = map[string]string{ LOGTAG_MYSQL_SUCCESS: LOGTAG_MYSQL_FAILURE, LOGTAG_MONGO_SUCCESS: LOGTAG_MONGO_FAILURE, LOGTAG_REDIS_SUCCESS: LOGTAG_REDIS_FAILURE, LOGTAG_THRIFT_SUCCESS: LOGTAG_THRIFT_FAILURE, LOGTAG_HTTP_SUCCESS: LOGTAG_HTTP_FAILURE, LOGTAG_PROXY_SUCCESS: LOGTAG_PROXY_FAILURE, LOGTAG_ENGINE_OK: LOGTAG_ENGINE_ERR, LOGTAG_ELASTIC_SUCCESS: LOGTAG_ELASTIC_FAILURE, }
Functions ¶
func CallerEncoder ¶
func CallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
func DurationEncoder ¶
func DurationEncoder(d time.Duration, enc zapcore.PrimitiveArrayEncoder)
func GetIntranetIpv4 ¶
func LevelEncoder ¶
func LevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
func NewFCLogEncoder ¶
func NewFCLogEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder
NewJSONEncoder creates a fast, low-allocation JSON encoder. The encoder appropriately escapes all field keys and values.
Note that the encoder doesn't deduplicate keys, so it's possible to produce a message like
{"foo":"bar","foo":"baz"}
This is permitted by the JSON specification, but not encouraged. Many libraries will ignore duplicate key-value pairs (typically keeping the last pair) when unmarshaling, but users should attempt to avoid adding duplicate keys.
func TimeEncoder ¶
func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
Types ¶
type Config ¶
type Config struct { RotateConfig `json:",inline" yaml:",inline"` // Level is the minimum enabled logging level. Note that this is a dynamic // level, so calling Config.Level.SetLevel will atomically change the log // level of all loggers descended from this config. Level zap.AtomicLevel `json:"level" yaml:"level"` // Development puts the logger in development mode, which changes the // behavior of DPanicLevel and takes stacktraces more liberally. Development bool `json:"development" yaml:"development"` // DisableCaller stops annotating logs with the calling function's file // name and line number. By default, all logs are annotated. DisableCaller bool `json:"disableCaller" yaml:"disableCaller"` // DisableStacktrace completely disables automatic stacktrace capturing. By // default, stacktraces are captured for WarnLevel and above logs in // development and ErrorLevel and above in production. DisableStacktrace bool `json:"disableStacktrace" yaml:"disableStacktrace"` // Sampling sets a sampling policy. A nil SamplingConfig disables sampling. Sampling *zap.SamplingConfig `json:"sampling" yaml:"sampling"` // OutputPaths is a list of URLs or file paths to write logging output to. // See Open for details. OutputPaths map[string][]string `json:"outputPaths" yaml:"outputPaths"` // InitialFields is a collection of fields to add to the root logger. InitialFields map[string]interface{} `json:"initialFields" yaml:"initialFields"` // max lines cached in memory before writing into files MaxQueueSize int64 `json:"maxQueueSize" yaml:"maxQueueSize"` INode uint64 LogId int64 }
type FCLogEncoder ¶
type FCLogEncoder struct { *zapcore.EncoderConfig // contains filtered or unexported fields }
func (*FCLogEncoder) AddArray ¶
func (enc *FCLogEncoder) AddArray(key string, arr zapcore.ArrayMarshaler) error
func (*FCLogEncoder) AddBinary ¶
func (enc *FCLogEncoder) AddBinary(key string, val []byte)
func (*FCLogEncoder) AddBool ¶
func (enc *FCLogEncoder) AddBool(key string, val bool)
func (*FCLogEncoder) AddByteString ¶
func (enc *FCLogEncoder) AddByteString(key string, val []byte)
func (*FCLogEncoder) AddComplex128 ¶
func (enc *FCLogEncoder) AddComplex128(key string, val complex128)
func (*FCLogEncoder) AddComplex64 ¶
func (enc *FCLogEncoder) AddComplex64(k string, v complex64)
func (*FCLogEncoder) AddDuration ¶
func (enc *FCLogEncoder) AddDuration(key string, val time.Duration)
func (*FCLogEncoder) AddFloat32 ¶
func (enc *FCLogEncoder) AddFloat32(k string, v float32)
func (*FCLogEncoder) AddFloat64 ¶
func (enc *FCLogEncoder) AddFloat64(key string, val float64)
func (*FCLogEncoder) AddInt ¶
func (enc *FCLogEncoder) AddInt(k string, v int)
func (*FCLogEncoder) AddInt16 ¶
func (enc *FCLogEncoder) AddInt16(k string, v int16)
func (*FCLogEncoder) AddInt32 ¶
func (enc *FCLogEncoder) AddInt32(k string, v int32)
func (*FCLogEncoder) AddInt64 ¶
func (enc *FCLogEncoder) AddInt64(key string, val int64)
func (*FCLogEncoder) AddInt8 ¶
func (enc *FCLogEncoder) AddInt8(k string, v int8)
func (*FCLogEncoder) AddObject ¶
func (enc *FCLogEncoder) AddObject(key string, obj zapcore.ObjectMarshaler) error
func (*FCLogEncoder) AddReflected ¶
func (enc *FCLogEncoder) AddReflected(key string, obj interface{}) error
func (*FCLogEncoder) AddString ¶
func (enc *FCLogEncoder) AddString(key, val string)
func (*FCLogEncoder) AddUint ¶
func (enc *FCLogEncoder) AddUint(k string, v uint)
func (*FCLogEncoder) AddUint16 ¶
func (enc *FCLogEncoder) AddUint16(k string, v uint16)
func (*FCLogEncoder) AddUint32 ¶
func (enc *FCLogEncoder) AddUint32(k string, v uint32)
func (*FCLogEncoder) AddUint64 ¶
func (enc *FCLogEncoder) AddUint64(key string, val uint64)
func (*FCLogEncoder) AddUint8 ¶
func (enc *FCLogEncoder) AddUint8(k string, v uint8)
func (*FCLogEncoder) AddUintptr ¶
func (enc *FCLogEncoder) AddUintptr(k string, v uintptr)
func (*FCLogEncoder) AppendArray ¶
func (enc *FCLogEncoder) AppendArray(arr zapcore.ArrayMarshaler) error
func (*FCLogEncoder) AppendBool ¶
func (enc *FCLogEncoder) AppendBool(val bool)
func (*FCLogEncoder) AppendByteString ¶
func (enc *FCLogEncoder) AppendByteString(val []byte)
func (*FCLogEncoder) AppendComplex128 ¶
func (enc *FCLogEncoder) AppendComplex128(val complex128)
func (*FCLogEncoder) AppendComplex64 ¶
func (enc *FCLogEncoder) AppendComplex64(v complex64)
func (*FCLogEncoder) AppendDuration ¶
func (enc *FCLogEncoder) AppendDuration(val time.Duration)
func (*FCLogEncoder) AppendFloat32 ¶
func (enc *FCLogEncoder) AppendFloat32(v float32)
func (*FCLogEncoder) AppendFloat64 ¶
func (enc *FCLogEncoder) AppendFloat64(v float64)
func (*FCLogEncoder) AppendInt ¶
func (enc *FCLogEncoder) AppendInt(v int)
func (*FCLogEncoder) AppendInt16 ¶
func (enc *FCLogEncoder) AppendInt16(v int16)
func (*FCLogEncoder) AppendInt32 ¶
func (enc *FCLogEncoder) AppendInt32(v int32)
func (*FCLogEncoder) AppendInt64 ¶
func (enc *FCLogEncoder) AppendInt64(val int64)
func (*FCLogEncoder) AppendInt8 ¶
func (enc *FCLogEncoder) AppendInt8(v int8)
func (*FCLogEncoder) AppendObject ¶
func (enc *FCLogEncoder) AppendObject(obj zapcore.ObjectMarshaler) error
func (*FCLogEncoder) AppendReflected ¶
func (enc *FCLogEncoder) AppendReflected(val interface{}) error
func (*FCLogEncoder) AppendString ¶
func (enc *FCLogEncoder) AppendString(val string)
func (*FCLogEncoder) AppendTime ¶
func (enc *FCLogEncoder) AppendTime(val time.Time)
func (*FCLogEncoder) AppendUint ¶
func (enc *FCLogEncoder) AppendUint(v uint)
func (*FCLogEncoder) AppendUint16 ¶
func (enc *FCLogEncoder) AppendUint16(v uint16)
func (*FCLogEncoder) AppendUint32 ¶
func (enc *FCLogEncoder) AppendUint32(v uint32)
func (*FCLogEncoder) AppendUint64 ¶
func (enc *FCLogEncoder) AppendUint64(val uint64)
func (*FCLogEncoder) AppendUint8 ¶
func (enc *FCLogEncoder) AppendUint8(v uint8)
func (*FCLogEncoder) AppendUintptr ¶
func (enc *FCLogEncoder) AppendUintptr(v uintptr)
func (*FCLogEncoder) Clone ¶
func (enc *FCLogEncoder) Clone() zapcore.Encoder
func (*FCLogEncoder) EncodeEntry ¶
EncodeEntry 组织日志输出
func (*FCLogEncoder) OpenNamespace ¶
func (enc *FCLogEncoder) OpenNamespace(key string)
type HintContent ¶
type HintContent struct {
Sample HintSampling `json:"Sample"`
}
type HintSampling ¶
type Logger ¶
var (
CommonLogger *Logger
)
func NewTestLogger ¶
func (*Logger) LogWithError ¶
func (*Logger) ParseTrace ¶
func (*Logger) SetTraceToWriter ¶
func (l *Logger) SetTraceToWriter(ctx context.Context, rw http.ResponseWriter)
type RotateConfig ¶
type RotateConfig struct { // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int `json:"maxsize" yaml:"maxsize"` // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int `json:"maxage" yaml:"maxage"` // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int `json:"maxbackups" yaml:"maxbackups"` MaxBackupSize int `json:"maxbackupsize" yaml:"maxbackupsize"` // Compress determines if the rotated log files should be compressed // using gzip. Compress bool `json:"compress" yaml:"compress"` }
type RotateWriter ¶
type RotateWriter struct { RotateConfig // Filename is the file to write logs to. Backup log files will be retained // in the same directory. It uses <processname>-lumberjack.log in // os.TempDir() if empty. Filename string `json:"filename" yaml:"filename"` // LocalTime determines if the time used for formatting the timestamps in // backup files is the computer's local time. The default is to use UTC // time. LocalTime bool `json:"localtime" yaml:"localtime"` INode uint64 // contains filtered or unexported fields }
func (*RotateWriter) Close ¶
func (l *RotateWriter) Close() error
Close implements io.Closer, and closes the current logfile.
func (*RotateWriter) OpenExistingOrNew ¶
func (l *RotateWriter) OpenExistingOrNew() error
func (*RotateWriter) PrefixAndExt ¶
func (l *RotateWriter) PrefixAndExt() (prefix, ext string)
func (*RotateWriter) Rotate ¶
func (l *RotateWriter) Rotate() error
Rotate causes RotateWriter to close the existing log file and immediately create a new one. This is a helper function for applications that want to initiate rotations outside of the normal rotation rules, such as in response to SIGHUP. After rotating, this initiates compression and removal of old log files according to the configuration.
func (*RotateWriter) TimeFromName ¶
func (*RotateWriter) Write ¶
func (l *RotateWriter) Write(p []byte) (n int, err error)
Write implements io.Writer. If a write would cause the log file to be larger than MaxSize, the file is closed, renamed to include a timestamp of the current time, and a new log file is created using the original log file name. If the length of the write is greater than MaxSize, an error is returned.
type Trace ¶
type Trace struct { TraceId string SpanId string HintCode int64 HintContent HintContent }
func GetTraceFromHeader ¶
GetTraceFromHeader 从http request中获取header中的trace信息
func (*Trace) GetHintCode ¶
func (*Trace) GetHintContent ¶
func (*Trace) GetTraceId ¶
type Writer ¶
type Writer interface { zapcore.WriteSyncer io.Closer }