log

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 10

README

Log

适配 OpenTracing 和 OpenTelemetry 的日志工具.

import "gitee.com/go-libs/log"

func main() {
// 等待完成.
// 主协程退出前, 等待日志和调用链全部上报完成.
defer log.Close()

...
}

1. 配置

本工具包首次加载时, 在项目的工作目录中查找 config/log.yamlconfig/log.yml../config/log.yaml../config/log.yml 文件, 然后解析到 go-libs/conf/Config 实例.

2. 日志

日志系统支持下列适配, 同时只能配置其中一项.

  • term - sync 在终端上打印日志.
  • file - async 日志写入到本地文件中.
  • kafka - async 发布日志到 Kafka 中间件.
  • elasticsearch - async 发布日志到 Elasticsearch 中间件.
2.1 简易用法
log.Info("info message")
log.Infof("info message with: %s", "formatter")

// 兼容 OpenTracing / OpenTelemetry.
ctx := log.NewContext()
log.Infofc(ctx, "info message with: %s", "formatter and context")
2.2 调整格式化
formatter := &MyFormatter{}
log.LoggingManager().GetPlugin().SetFormatter(formatter)

3. 调用链

Trace reporter support follow adapters.

  • jaeger - publish span to jaeger
  • zipkin - publish span to zipkin
3.1 简易用法
span := log.NewSpan("example")
defer span.End()

span.Info("info message")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AttachRequest  = common.AttachRequest
	ContextHeader  = common.GetContextHeader
	ContextTracing = common.GetContextTracing
	Context        = common.NewContext
	NewContext     = common.NewContext
)
View Source
var (
	NewSpan            = tracer.NewSpan
	NewSpanWithContext = tracer.NewSpanWithContext
	NewSpanWithHeader  = tracer.NewSpanWithHeader
	NewSpanWithRequest = tracer.NewSpanWithRequest
)
View Source
var (
	NewTracing            = common.NewTracing
	NewTracingWithContext = common.NewTracingWithContext
	NewTracingWithHeader  = common.NewTracingWithHeader
	NewTracingWithRequest = common.NewTracingWithRequest
)
View Source
var (
	Debug   = logger.Debug
	Debugf  = logger.Debugf
	Debugfc = logger.Debugfc
	Error   = logger.Error
	Errorf  = logger.Errorf
	Errorfc = logger.Errorfc
	Fatal   = logger.Fatal
	Fatalf  = logger.Fatalf
	Fatalfc = logger.Fatalfc
	Info    = logger.Info
	Infof   = logger.Infof
	Infofc  = logger.Infofc
	Panic   = logger.Fatal
	Panicf  = logger.Fatalf
	Panicfc = logger.Fatalfc
	Warn    = logger.Warn
	Warnf   = logger.Warnf
	Warnfc  = logger.Warnfc
)
View Source
var (
	Config = conf.New
)
View Source
var (
	LoggingManager = logger.New
)
View Source
var (
	SpanManager = tracer.New
)

Functions

func Close

func Close()

Close 关闭日志, 此过程阻塞协程, 直到所有链路跟踪与日志上报完成.

Types

type Level added in v1.1.1

type Level = base.Level

type Span

type Span = common.Span

type Tracer added in v1.1.1

type Tracer = base.Tracer

type Tracing

type Tracing = common.Tracing

Directories

Path Synopsis
zipkin_plugin/model
Package model contains the Zipkin V2 model which is used by the Zipkin Go tracer implementation.
Package model contains the Zipkin V2 model which is used by the Zipkin Go tracer implementation.

Jump to

Keyboard shortcuts

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