xlog

package
v0.0.0-...-80fcaa9 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SetFormatter    = xLOG.SetFormatter
	SetOutput       = xLOG.SetOutput
	SetLevel        = xLOG.SetLevel
	SetReportCaller = xLOG.SetReportCaller
	Info            = xLOG.Info
	Infof           = xLOG.Infof
	Error           = xLOG.Error
	Errorf          = xLOG.Errorf
	Trace           = xLOG.Trace
	Tracef          = xLOG.Tracef
	WithFields      = xLOG.WithFields
)

Functions

func Carriers

func Carriers(ctx context.Context, op ...string) opentracing.TextMapCarrier

func Close

func Close()

关闭tracer

func ContextByCarrier

func ContextByCarrier(carrier opentracing.TextMapCarrier, operationName string, tag ...string) (ctx context.Context)

func CtxLog

func CtxLog(ctx context.Context) *logrus.Entry

ContextLog ContextLog

func Elapsed

func Elapsed(st time.Time, l ...*logrus.Entry) *logrus.Entry

func Err

func Err(err error, l ...*logrus.Entry) *logrus.Entry

func GetServiceName

func GetServiceName() string

func InitFromConfig

func InitFromConfig(c *Config) (err error)

从配置文件初始化

func InitFromEnv

func InitFromEnv() (err error)

从环境变量读取配置初始化

func InitOnlyTracingLog

func InitOnlyTracingLog(serviceName string) error

只生成链式日志,无需jaeger服务,不采样,不上报

func Logger

func Logger() *logrus.Logger

func RequestID

func RequestID(ctx context.Context) string

func StartContext

func StartContext(ctx context.Context, operationName string) context.Context

func Std

func Std() *logrus.Logger

Std Std log

func TraceID

func TraceID(ctx context.Context) string

Types

type Config

type Config struct {
	ServiceName         string  `json:"ServiceName" yaml:"ServiceName"`                 //服务名, 必须
	JaegerAgent         string  `json:"JaegerAgent" yaml:"JaegerAgent"`                 //jaeger-agent地址,可选: 默认:jaeger-agent:6831
	SamplerRateLimit    float64 `json:"SamplerRateLimit" yaml:"SamplerRateLimit"`       //<=0 永不上报,< 1 按固定概率上报,> 1 限制每秒最大上报数量,=1 总是上报
	QueueSize           int     `json:"QueueSize" yaml:"QueueSize"`                     //异步span队列最大大小,可选:默认100
	BufferFlushInterval int     `json:"BufferFlushInterval" yaml:"BufferFlushInterval"` //buff刷新间隔,可选:默认1  单位:秒
}

Config 配置文件

type JSONLoggerFormatter

type JSONLoggerFormatter struct {
}

func (JSONLoggerFormatter) Format

func (formatter JSONLoggerFormatter) Format(entry *logrus.Entry) ([]byte, error)

FormatDefault = "[${serviceName},${traceID},${spanID},${parentSpanID}][${pid}]"

timestamp := entry.Time.Format("2006-01-02 15:04:05")

return []byte(fmt.Sprintf("%s %s %s\n", timestamp, strings.ToUpper(entry.Level.String()), entry.Message)), nil

type MDReaderWriter

type MDReaderWriter struct {
	metadata.MD
}

func (MDReaderWriter) ForeachKey

func (c MDReaderWriter) ForeachKey(handler func(key, val string) error) error

func (MDReaderWriter) Set

func (c MDReaderWriter) Set(key, val string)

type TextLoggerFormatter

type TextLoggerFormatter struct {
}

func (TextLoggerFormatter) Format

func (formatter TextLoggerFormatter) Format(entry *logrus.Entry) ([]byte, error)

FormatDefault = "[${serviceName},${traceID},${spanID},${parentSpanID}][${pid}]"

timestamp := entry.Time.Format("2006-01-02 15:04:05")

return []byte(fmt.Sprintf("%s %s %s\n", timestamp, strings.ToUpper(entry.Level.String()), entry.Message)), nil

Jump to

Keyboard shortcuts

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