zero_mdc_log

package module
v0.0.0-...-3ddd8e8 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: AGPL-3.0 Imports: 16 Imported by: 1

README

zero_mdc_log

Description

zerolog with MDC。在overlog的基础上进行封装。

使用

可以参考otel_zero的使用方法。

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGlobalFields

func AddGlobalFields(field string)

func ClearGlobalFields

func ClearGlobalFields()

func FullCallerEncoder

func FullCallerEncoder() func(file string, line int) string

拼接文件和行号

func GetGlobalFields

func GetGlobalFields() []string

func GetGoroutineID

func GetGoroutineID() uint64

func GetZeroLogger

func GetZeroLogger() *zerolog.Logger

func LowercaseLevelEncoder

func LowercaseLevelEncoder() func(l zerolog.Level) string

这个为什么叫Lowercase呢,默认就是小写?

func ResetGlobalMdcAdapter

func ResetGlobalMdcAdapter()

func SetGlobalFields

func SetGlobalFields(fields []string)

func SetLogger

func SetLogger(configItems ...ConfigItem) gin.HandlerFunc

func ShortCallerEncoder

func ShortCallerEncoder() func(file string, line int) string

只有文件没有路径

func TrimmedPath

func TrimmedPath(file string) string

只有文件没有路径

func UppercaseLevelEncoder

func UppercaseLevelEncoder() func(l zerolog.Level) string

func Z

func Z() *zerolog.Logger

这是原本的zerolog

Types

type Config

type Config struct {
	Logger *zerolog.Logger // 需要传
	// UTC a boolean stating whether to use UTC time zone or local.
	UTC            bool           // 默认即可
	SkipPath       []string       // 默认即可
	SkipPathRegexp *regexp.Regexp // 默认即可
	// contains filtered or unexported fields
}

type ConfigItem

type ConfigItem interface {
	// contains filtered or unexported methods
}

func SetAppId

func SetAppId(appId string) ConfigItem

func SetEnvtype

func SetEnvtype(envType string) ConfigItem

ConfigEnvtype 环境

func SetRequestIdKey

func SetRequestIdKey(requestIdKey string) ConfigItem

func SetSessionid

func SetSessionid(sessionIdKey string) ConfigItem

func SetUserIdKey

func SetUserIdKey(userIdKey string) ConfigItem

type MDCHook

type MDCHook struct{}

func (MDCHook) Run

func (m MDCHook) Run(e *zerolog.Event, level zerolog.Level, message string)

将MDC的<key,value>放到fileds

type MdcAdapter

type MdcAdapter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func InitGlobalMdcAdapter

func InitGlobalMdcAdapter() *MdcAdapter

func MDC

func MDC() *MdcAdapter

func (*MdcAdapter) Count

func (m *MdcAdapter) Count() int

func (*MdcAdapter) Get

func (m *MdcAdapter) Get(key string) (interface{}, bool)

func (*MdcAdapter) GetString

func (m *MdcAdapter) GetString(key string) string

func (*MdcAdapter) Has

func (m *MdcAdapter) Has(key string) bool

func (*MdcAdapter) IsEmpty

func (m *MdcAdapter) IsEmpty() bool

func (*MdcAdapter) Keys

func (m *MdcAdapter) Keys() []string

func (*MdcAdapter) Remove

func (m *MdcAdapter) Remove(key string)

func (*MdcAdapter) Set

func (m *MdcAdapter) Set(key string, value interface{})

func (*MdcAdapter) SetIfAbsent

func (m *MdcAdapter) SetIfAbsent(key string, value interface{}) bool

func (*MdcAdapter) SetMap

func (m *MdcAdapter) SetMap(data map[string]interface{})

type Overlog

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

func Log

func Log() *Overlog

这是logger

func New

func New(logger zerolog.Logger) *Overlog

func NewDefault

func NewDefault() *Overlog

func (*Overlog) Debug

func (o *Overlog) Debug() *zerolog.Event
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().ODebug("hello world")
Output:

{"level":"debug","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Debugf

func (o *Overlog) Debugf(format string, args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Debugf("hello %s", "world")
Output:

{"level":"debug","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Error

func (o *Overlog) Error() *zerolog.Event
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().OError("hello world")
Output:

{"level":"error","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Errorf

func (o *Overlog) Errorf(format string, args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Errorf("hello %s", "world")
Output:

{"level":"error","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Fatal

func (o *Overlog) Fatal(args ...interface{})

func (*Overlog) Fatalf

func (o *Overlog) Fatalf(format string, args ...interface{})

func (*Overlog) Info

func (o *Overlog) Info() *zerolog.Event
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().OInfo("hello world")
Output:

{"level":"info","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Infof

func (o *Overlog) Infof(format string, args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Infof("hello %s", "world")
Output:

{"level":"info","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Log

func (o *Overlog) Log(args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Log("hello world")
Output:

{"x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Logf

func (o *Overlog) Logf(format string, args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Logf("hello %s", "world")
Output:

{"x-correlation-id":"1234","message":"hello world"}

func (*Overlog) ODebug

func (o *Overlog) ODebug(args ...interface{})

func (*Overlog) OError

func (o *Overlog) OError(args ...interface{})

func (*Overlog) OInfo

func (o *Overlog) OInfo(args ...interface{})

func (*Overlog) OPanic

func (o *Overlog) OPanic(args ...interface{})

func (*Overlog) Panic

func (o *Overlog) Panic() *zerolog.Event

func (*Overlog) Panicf

func (o *Overlog) Panicf(format string, args ...interface{})

func (*Overlog) Print

func (o *Overlog) Print(args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Print("hello world")
Output:

{"level":"debug","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Printf

func (o *Overlog) Printf(format string, args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Printf("hello %s", "world")
Output:

{"level":"debug","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Trace

func (o *Overlog) Trace(args ...interface{})

这么封装就失去了原本的用法

Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Trace("hello world")
Output:

{"level":"trace","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Tracef

func (o *Overlog) Tracef(format string, args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Tracef("hello %s", "world")
Output:

{"level":"trace","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Warn

func (o *Overlog) Warn(args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Warn("hello world")
Output:

{"level":"warn","x-correlation-id":"1234","message":"hello world"}

func (*Overlog) Warnf

func (o *Overlog) Warnf(format string, args ...interface{})
Example
New(zerolog.New(os.Stdout))
MDC().Set("x-correlation-id", "1234")
AddGlobalFields("x-correlation-id")

Log().Warnf("hello %s", "world")
Output:

{"level":"warn","x-correlation-id":"1234","message":"hello world"}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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