log

package module
v2.0.16 Latest Latest
Warning

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

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

README

logger

License

  1. 包名: github.com/fuyibing/log/v2.
  2. 版本: v2

本包在导入后, 扫描 tmp/log.yamlconfig/log.yaml 并初始化, 详细配置参见本包的 config/log.yaml 注释.

通用用法.
log.Info("message.")
log.Infof("message %d: %s.", 1, "parse", "example")
带请求链
ctx := log.NewContext()
log.Debugfc(ctx, "debug fc")
log.Infofc(ctx, "info fc")
log.Warnfc(ctx, "warn fc")
log.Errorfc(ctx, "error fc")
在IRIS框架中

首先通过中间件, 在入口注册请求链.

log.BindRequest(iris.Request())

在IRIS框架中使用.

ctx := iris.Request().Context()

log.Debugfc(ctx, "debug fc")
log.Infofc(ctx, "info fc")
log.Warnfc(ctx, "warn fc")
log.Errorfc(ctx, "error fc")

自定义日志处理.
log.Config.SetHandler(func(line interfaces.LineInterface) {
    println("handler: ", line.SpanVersion(), line.Content())
})

ctx := log.NewContext()
log.Debugfc(ctx, "debug fc")
log.Infofc(ctx, "info fc")
log.Warnfc(ctx, "warn fc")
log.Errorfc(ctx, "error fc")

Documentation

Index

Constants

This section is empty.

Variables

Functions

func ChildContext

func ChildContext(ctx interface{}, text string, args ...interface{}) context.Context

子级上下文.

func Debug

func Debug(text string)

添加Debug日志.

func Debugf

func Debugf(text string, args ...interface{})

添加Debug日志, 支持格式化.

func Debugfc

func Debugfc(ctx interface{}, text string, args ...interface{})

添加Debug日志, 支持格式化和请求链.

func Error

func Error(text string)

添加Error日志.

func Errorf

func Errorf(text string, args ...interface{})

添加Error日志, 支持格式化.

func Errorfc

func Errorfc(ctx interface{}, text string, args ...interface{})

添加Error日志, 支持格式化和请求链.

func Info

func Info(text string)

添加Info日志.

func Infof

func Infof(text string, args ...interface{})

添加Info日志, 支持格式化.

func Infofc

func Infofc(ctx interface{}, text string, args ...interface{})

添加Info日志, 支持格式化和请求链.

func IrisBind

func IrisBind(ctx iris.Context)

绑定Tracing. 在请求的入口进行绑定, 请求过程即可复用. 整个业务过程中使用 绑定后的Context, 可以保障同一个请求下的日志含相同的Span、 Trace待标识.

func NewContext

func NewContext() context.Context

创建上下文.

func NewLine

func NewLine(ctx interface{}, level interfaces.Level, text string, args []interface{}) interfaces.LineInterface

创建日志行实例.

func NewTracing

func NewTracing() interfaces.TraceInterface

创建OpenTracing.

func Panic

func Panic(text string)

func Panicf

func Panicf(text string, args ...interface{})

func Panicfc

func Panicfc(ctx interface{}, text string, args ...interface{})

func ParseTracing

func ParseTracing(ctx interface{}) interfaces.TraceInterface

解析Tracing.

func ParseTracingToRequest

func ParseTracingToRequest(ctx interface{}, req *http.Request)

func Warn

func Warn(text string)

添加Warn日志.

func Warnf

func Warnf(text string, args ...interface{})

添加Warn日志, 支持格式化.

func Warnfc

func Warnfc(ctx interface{}, text string, args ...interface{})

添加Warn日志, 支持格式化和请求链.

Types

type Line

type Line struct {
	// contains filtered or unexported fields
}

日志行结构体.

func (*Line) ColorLevel

func (o *Line) ColorLevel() string

返回带颜色Level文本.

func (*Line) Content

func (o *Line) Content() string

日志正文.

func (*Line) Duration

func (o *Line) Duration() float64

执行时长.

func (*Line) Level

func (o *Line) Level() string

日志级别.

func (*Line) ParentSpanId

func (o *Line) ParentSpanId() string

上级Span.

func (*Line) Pid

func (o *Line) Pid() int

进程ID.

func (*Line) RequestInfo

func (o *Line) RequestInfo() (method string, url string)

请求信息.

func (*Line) ServiceAddr

func (o *Line) ServiceAddr() string

func (*Line) ServiceName

func (o *Line) ServiceName() string

func (*Line) SpanId

func (o *Line) SpanId() string

func (*Line) SpanVersion

func (o *Line) SpanVersion() string

func (*Line) Time

func (o *Line) Time() time.Time

func (*Line) Timeline

func (o *Line) Timeline() string

func (*Line) TraceId

func (o *Line) TraceId() string

func (*Line) Tracing

func (o *Line) Tracing() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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