log

package
v0.0.0-...-cb3c958 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(dsn string)

func NewTraceContext

func NewTraceContext(traceID string) context.Context

NewTraceContext new context with a traceID

func WithContext

func WithContext(ctx context.Context) *zap.Logger

WithContext 从指定的context返回一个zap实例(关键方法)

func WithName

func WithName(name string) *zap.Logger

Types

type Config

type Config struct {
	Encoder    string   // 编码器: console, json
	Outputs    []string // 日志输出方式 stdout, file
	Parameters struct {
		Level         string // level 日志输出级别: e.g. debug, info, warn, error
		TraceLevel    string // trace_level 是否开启错误上下文追踪
		TimeEncoder   string // time_encoder 时间编码器(时间格式)
		CallerEncoder string // caller_encoder 调用者格式 e.g. short, full
		FilePath      string // file_path output包含file时需要此参数
	}
}

Config config

func ParseConfig

func ParseConfig(dsn string) (*Config, error)

ParseConfig parse config from dsn dsn e.g. console://[stdout,file]?level=debug&trace_level=error

type Logger

type Logger struct {
	ZapLogger *zap.Logger
}
var DefaultLogger *Logger

DefaultLogger default logger

func New

func New(dsn string) (*Logger, error)

func (*Logger) WithContext

func (receiver *Logger) WithContext(ctx context.Context) *zap.Logger

type TraceIDKeyType

type TraceIDKeyType string

TraceIDKeyType trace id key type

const (
	// TraceIDKey trace id key
	TraceIDKey TraceIDKeyType = "traceId"
)

Jump to

Keyboard shortcuts

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