log

package
v0.0.0-...-221f2c5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SystemKey = "system"
View Source
var SystemName = "system"
View Source
var SystemTraceName = "system"

Functions

func GetTraceIDFromContext

func GetTraceIDFromContext(ctx context.Context) string

GetTraceIDFromContext GetTraceIDFromContext

func GetTraceIDFromGrpcMetadata

func GetTraceIDFromGrpcMetadata(md metadata.MD) string

GetTraceIDFromGrpcMetadata GetTraceIDFromGrpcMetadata case insensitive

func GetTraceIDFromHTTPHeader

func GetTraceIDFromHTTPHeader(header http.Header) string

GetTraceIDFromHTTPHeader GetTraceIDFromHTTPHeader

func L

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

Logger with log-id field

func New

func New(conf Config) (*zap.Logger, error)

New new a zap.Logger

func NewCtxWithTraceID

func NewCtxWithTraceID(ctx context.Context) context.Context

NewCtxWithTraceID NewCtxWithTraceID

func NewTraceID

func NewTraceID() string

NewTraceID return a random string

func S

S SugaredLogger with log-id field

func TraceIDField

func TraceIDField(ctx context.Context) zap.Field

TraceIDField TraceIDField

Types

type Config

type Config struct {
	// 业务服务名称,如果多个业务日志在ELK中聚合,此字段就有用了
	ServiceName string `yaml:"serviceName"`
	// 日志级别.
	Level string `yaml:"level"`
	// 日志级别字段开启颜色功能
	LevelColor bool `yaml:"levelColor"`
	// Log format. one of json or plain.
	Format string `yaml:"format"`
	// 是否输出到控制台.
	Stdout bool `yaml:"stdout"`
	// File log config.
	File FileLogConfig `yaml:"file"`
	//EncodeKey EncodeKeys
	EncodeKey EncodeKeyConfig `yaml:"encodeKey"`
	//SentryDSN Sentry 的 DSN地址,如果配置了此参数,warn 级别以上的错误会发送sentry
	SentryDSN string `yaml:"sentryDSN"`
	//SystemName 系统名称
	SystemName string `yaml:"systemName"`
	//SystemTraceName 系统日志(非业务相关) traceID 对应的值
	SystemTraceName string `yaml:"systemTraceName"`
}

type EncodeKeyConfig

type EncodeKeyConfig struct {
	// TimeKey format.
	TimeKey string `yaml:"timeKey"`
	// LevelKey format.
	LevelKey string `yaml:"levelKey"`
	// NameKey format.
	NameKey string `yaml:"nameKey"`
	// CallerKey format.
	CallerKey string `yaml:"callerKey"`
	// MessageKey format.
	MessageKey string `yaml:"messageKey"`
	//StacktraceKey StacktraceKey
	StacktraceKey string `yaml:"stacktraceKey"`
}

type FileLogConfig

type FileLogConfig struct {
	// Filename 日志文件路径.
	Filename string `yaml:"filename"`
	// LogRotate Is log rotate enabled.
	LogRotate bool `yaml:"logRotate"`
	// MaxSize size for a single file, in MB.
	MaxSize int `yaml:"maxSize"`
	// MaxAge log keep days, default is never deleting.
	MaxAge int `yaml:"maxAge"`
	// MaxBackups  number of old log files to retain.
	MaxBackups int `yaml:"maxBackups"`
	// BufSize  size of bufio.Writer
	BufSize int `yaml:"bufSize"`
}

FileLogConfig serializes file log related config.

type ID

type ID struct {
	High, Low uint64
}

ID traceID

func (ID) IsValid

func (o ID) IsValid() bool

IsValid checks if the ID is valid, i.e. not zero.

func (ID) String

func (o ID) String() string

String String

type TraceKey

type TraceKey string
const TraceKeyName TraceKey = "X-Request-ID"

TraceKeyName http stander header style

Jump to

Keyboard shortcuts

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