log

package
v0.0.0-...-d3f65ed Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 11 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultCaller is a Valuer that returns the file and line.
	DefaultCaller = Caller(3)

	// DefaultTimestamp is a Valuer that returns the current wallclock time.
	DefaultTimestamp = Timestamp(time.RFC3339)
)

Functions

func Value

func Value(ctx context.Context, value interface{}) interface{}

Value 尝试调用Valuer接口返回

Types

type Helper

type Helper struct {
	Logger
}

func NewHelper

func NewHelper(log Logger) *Helper

NewHelper 实例化函数

func (*Helper) Debug

func (h *Helper) Debug(a ...interface{})

Debug .

func (*Helper) Debugf

func (h *Helper) Debugf(format string, a ...interface{})

Debugf .

func (*Helper) Debugw

func (h *Helper) Debugw(keyvals ...interface{})

Debugw .

func (*Helper) Error

func (h *Helper) Error(a ...interface{})

Error .

func (*Helper) Errorf

func (h *Helper) Errorf(format string, a ...interface{})

Errorf .

func (*Helper) Errorw

func (h *Helper) Errorw(keyvals ...interface{})

Errorw .

func (*Helper) Info

func (h *Helper) Info(a ...interface{})

Info .

func (*Helper) Infof

func (h *Helper) Infof(format string, a ...interface{})

Infof .

func (*Helper) Infow

func (h *Helper) Infow(keyvals ...interface{})

Infow .

func (*Helper) Log

func (h *Helper) Log(lever Lever, kvs ...interface{})

Log .

func (*Helper) Warn

func (h *Helper) Warn(a ...interface{})

Warn .

func (*Helper) Warnf

func (h *Helper) Warnf(format string, a ...interface{})

Warnf .

func (*Helper) Warnw

func (h *Helper) Warnw(keyvals ...interface{})

Warnw .

func (*Helper) WithContext

func (h *Helper) WithContext(ctx context.Context) *Helper

WithContext 调用 logger WithContext 刷新ctx

type Lever

type Lever int8
const (
	LevelDebug Lever = iota
	LevelInfo
	LevelWarn
	LevelError
)

预定义Level等级

func (Lever) Allow

func (l Lever) Allow(lv Lever) bool

Allow 允许是否可以打印

func (Lever) String

func (l Lever) String() string

String 语义转义

type Logger

type Logger interface {
	Log(lever Lever, kv ...interface{}) error
}

Logger 操作日志对外的接口 实现该接口需要保证它是并发安全的

var DefaultLogger Logger = NewStdLogger(log.Writer())

DefaultLogger is default logger.

func NewStdLogger

func NewStdLogger(w io.Writer) Logger

NewStdLogger new a logger with writer.

func With

func With(l Logger, kvs ...interface{}) Logger

With 生成 Logger

func WithContext

func WithContext(ctx context.Context, l Logger) Logger

WithContext 设置 Logger 上下文

func WithLogs

func WithLogs(logs ...Logger) Logger

WithLogs 包装多个 Logger

type Valuer

type Valuer func(ctx context.Context) interface{}

Valuer log返回携带值

func Caller

func Caller(depth int) Valuer

Caller 返回调用方的堆信息

func SpanID

func SpanID() Valuer

SpanID 返回链路定位的 SpanID Valuer SpanID 代表本次调用在整个调用链路树中的位置

func Timestamp

func Timestamp(layout string) Valuer

Timestamp 返回指定layout的时间戳 Valuer

func TraceID

func TraceID() Valuer

TraceID 返回链路追踪使用的tranceID Valuer TraceID 来将一个请求在各个服务器上的调用日志串联起来

Jump to

Keyboard shortcuts

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