trace

package
v0.0.0-...-a2bc238 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	LOGKEY_BEGIN = "__TIME__"
	LOGKEY_TAG   = "tag"
)
View Source
const (
	LOG_OK = "ok"
)
View Source
const (
	LOG_TIME_FORMAT = "[2006-01-02 15:04:05.000-0700]"
)
View Source
const (
	X_REQUEST_HEADER_RID = "X-Request-Id"
)

Variables

View Source
var ErrMissingLevel = errors.New("missing level")

Functions

func CallerEncoder

func CallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)

func DPanic

func DPanic(msg string, fields ...zap.Field)

func DPanicf

func DPanicf(format string, v ...interface{})

func DPanicln

func DPanicln(v ...interface{})

func Debug

func Debug(msg string, fields ...zap.Field)

func Debugf

func Debugf(format string, v ...interface{})

func Debugln

func Debugln(v ...interface{})

func DurationEncoder

func DurationEncoder(d time.Duration, enc zapcore.PrimitiveArrayEncoder)

func Error

func Error(msg string, fields ...zap.Field)

func Errorf

func Errorf(format string, v ...interface{})

func Errorln

func Errorln(v ...interface{})

func Fatal

func Fatal(msg string, fields ...zap.Field)

func Fatalf

func Fatalf(format string, v ...interface{})

func Fataln

func Fataln(v ...interface{})

func GenTraceId

func GenTraceId(ctx context.Context) (traceId string)

GenTraceId 生成traceid

func GetIntranetIpv4

func GetIntranetIpv4() (ip string, err error)

func GetIp

func GetIp() string

func Info

func Info(msg string, fields ...zap.Field)

func Infof

func Infof(format string, v ...interface{})

func Infoln

func Infoln(v ...interface{})

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 NewSpanId

func NewSpanId(ctx context.Context) string

func Panic

func Panic(msg string, fields ...zap.Field)

func Panicf

func Panicf(format string, v ...interface{})

func Panicln

func Panicln(v ...interface{})

func Print

func Print(msg string, fields ...zap.Field)

func Printf

func Printf(format string, v ...interface{})

func Println

func Println(v ...interface{})

func SetConfig

func SetConfig(c Config, logDir string)

func TimeEncoder

func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func Warn

func Warn(msg string, fields ...zap.Field)

func Warnf

func Warnf(format string, v ...interface{})

func Warnln

func Warnln(v ...interface{})

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) AddTime

func (enc *FCLogEncoder) AddTime(key string, val time.Time)

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

func (enc *FCLogEncoder) EncodeEntry(ent zapcore.Entry, fields []zap.Field) (*buffer.Buffer, error)

EncodeEntry 组织日志输出

func (*FCLogEncoder) OpenNamespace

func (enc *FCLogEncoder) OpenNamespace(key string)

type Fields

type Fields = []zap.Field

func BeginWith

func BeginWith(tag string, st ...time.Time) Fields

type HintContent

type HintContent struct {
	Sample HintSampling `json:"Sample"`
}

type HintSampling

type HintSampling struct {
	Rate int   `json:"Rate"`
	Code int64 `json:"Code"`
}

type Logger

type Logger struct {
	*zap.Logger

	*Trace
	LogId int64
	// contains filtered or unexported fields
}
var (
	CommonLogger *Logger
)

func NewLogger

func NewLogger(logId int64, module string) *Logger

func NewTestLogger

func NewTestLogger(logId int64) *Logger

func (*Logger) Clone

func (l *Logger) Clone() *Logger

func (*Logger) ClonePure

func (l *Logger) ClonePure() *Logger

func (*Logger) DPanic

func (l *Logger) DPanic(msg string, fields ...zap.Field)

func (*Logger) DPanicf

func (l *Logger) DPanicf(format string, v ...interface{})

func (*Logger) DPanicln

func (l *Logger) DPanicln(v ...interface{})

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zap.Field)

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

func (*Logger) Debugln

func (l *Logger) Debugln(v ...interface{})

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...zap.Field)

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

func (*Logger) Errorln

func (l *Logger) Errorln(v ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...zap.Field)

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

func (*Logger) Fataln

func (l *Logger) Fataln(v ...interface{})

func (*Logger) GetTrace

func (l *Logger) GetTrace(ctx context.Context) *Trace

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zap.Field)

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

func (*Logger) Infoln

func (l *Logger) Infoln(v ...interface{})

func (*Logger) LogWithError

func (logger *Logger) LogWithError(err error, fieldss ...Fields)

func (*Logger) Named

func (l *Logger) Named(s string) *Logger

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...zap.Field)

func (*Logger) Panicf

func (l *Logger) Panicf(format string, v ...interface{})

func (*Logger) Panicln

func (l *Logger) Panicln(v ...interface{})

func (*Logger) ParseTrace

func (l *Logger) ParseTrace(req *http.Request)

func (*Logger) Print

func (l *Logger) Print(msg string, fields ...zap.Field)

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

func (*Logger) Println

func (l *Logger) Println(v ...interface{})

func (*Logger) ResetTrace

func (l *Logger) ResetTrace(ctx context.Context) *Trace

func (*Logger) SetTraceToWriter

func (l *Logger) SetTraceToWriter(ctx context.Context, rw http.ResponseWriter)

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...zap.Field)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

func (*Logger) Warnln

func (l *Logger) Warnln(v ...interface{})

func (*Logger) With

func (l *Logger) With(fields ...zap.Field) *Logger

func (*Logger) WithBF

func (l *Logger) WithBF(ctx context.Context) *Logger

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 (l *RotateWriter) TimeFromName(filename, prefix, ext string, compress bool) (time.Time, error)

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

func GetTraceFromHeader(request *http.Request) (t *Trace)

GetTraceFromHeader 从http request中获取header中的trace信息

func (*Trace) GetHintCode

func (t *Trace) GetHintCode() string

func (*Trace) GetHintContent

func (t *Trace) GetHintContent() string

func (*Trace) GetSpanId

func (t *Trace) GetSpanId() string

func (*Trace) GetTraceId

func (t *Trace) GetTraceId() string

type Writer

type Writer interface {
	zapcore.WriteSyncer
	io.Closer
}

func NewAsyncRotateWriter

func NewAsyncRotateWriter(cfg *Config, module string) Writer

func NewAsyncWriter

func NewAsyncWriter(writer Writer) Writer

func NewRotateWriter

func NewRotateWriter(cfg *Config, module string) Writer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL