logger

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ModuleHTTP  = "HTTP"
	ModuleRPC   = "RPC"
	ModuleMySQL = "MySQL"
	ModuleRedis = "Redis"
	ModuleQueue = "Queue"
	ModuleCron  = "Cron"
)
View Source
const (
	AppName        = "app_name"
	LogID          = "log_id"
	TraceID        = "trace_id"
	Module         = "module"
	ServiceName    = "service_name"
	RequestHeader  = "request_header"
	ResponseHeader = "response_header"
	Method         = "method"
	API            = "api"
	URI            = "uri"
	Request        = "request"
	Response       = "response"
	Status         = "status"
	ClientIP       = "client_ip"
	ClientPort     = "client_port"
	ServerIP       = "server_ip"
	ServerPort     = "server_port"
	Cost           = "cost"
	Errno          = "errno"
)
View Source
const (
	LogHeader = "Log-Id"
)

Variables

This section is empty.

Functions

func AddField

func AddField(ctx context.Context, fields ...Field)

func DeleteField added in v1.0.9

func DeleteField(ctx context.Context, keys ...string)

func ExtractLogID

func ExtractLogID(req *http.Request) string

ExtractLogID init log id

func ForkContext added in v1.0.9

func ForkContext(ctx context.Context) context.Context

func ForkContextOnlyMeta added in v1.0.11

func ForkContextOnlyMeta(ctx context.Context) context.Context

func GetRequestBody

func GetRequestBody(req *http.Request) []byte

GetRequestBody get http request body

func InitFieldsContainer added in v1.0.9

func InitFieldsContainer(ctx context.Context) context.Context

func RangeFields added in v1.0.9

func RangeFields(ctx context.Context, f func(f Field))

func RotateWriter

func RotateWriter(infoFile, errFile string) (infoWriter io.Writer, errWriter io.Writer, err error)

func SetLogID added in v1.0.10

func SetLogID(ctx context.Context, header http.Header) (err error)

Types

type Field

type Field interface {
	Key() string
	Value() any
}

func Error

func Error(err any) Field

func ExtractFields added in v1.0.9

func ExtractFields(ctx context.Context) []Field

func FindField added in v1.0.9

func FindField(ctx context.Context, key string) Field

func Reflect

func Reflect(key string, value any) Field

func Stack added in v1.0.11

func Stack(s string) Field

type Fields

type Fields struct {
	AppName        string      `json:"app_name"`
	LogID          string      `json:"log_id"`
	TraceID        string      `json:"trace_id"`
	Module         string      `json:"module"`
	ServiceName    string      `json:"service_name"`
	RequestHeader  http.Header `json:"request_header"`
	ResponseHeader http.Header `json:"response_header"`
	Method         string      `json:"method"`
	API            string      `json:"api"`
	URI            string      `json:"uri"`
	Request        interface{} `json:"request"`
	Response       interface{} `json:"response"`
	Code           int         `json:"code"`
	ClientIP       string      `json:"client_ip"`
	ClientPort     int         `json:"client_port"`
	ServerIP       string      `json:"server_ip"`
	ServerPort     int         `json:"server_port"`
	Cost           int64       `json:"cost"`
	Error          string      `json:"error"`
	Stack          string      `json:"stack"`
}

type Level

type Level int8
const (
	UnknownLevel Level = iota - 1

	DebugLevel

	InfoLevel

	WarnLevel

	ErrorLevel

	FatalLevel
)

func StringToLevel

func StringToLevel(l string) Level

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Debug(ctx context.Context, msg string, fields ...Field)
	Info(ctx context.Context, msg string, fields ...Field)
	Warn(ctx context.Context, msg string, fields ...Field)
	Error(ctx context.Context, msg string, fields ...Field)
	DPanic(ctx context.Context, msg string, fields ...Field)
	Panic(ctx context.Context, msg string, fields ...Field)
	Fatal(ctx context.Context, msg string, fields ...Field)
	GetLevel() Level
	Close() error
}

type ObjectID

type ObjectID [12]byte

LogId is a unique ID identifying a log record. It must be exactly 12 bytes long.

Reference:http://www.mongodb.org/display/DOCS/Object+IDs

func NewObjectID

func NewObjectID() ObjectID

NewObjectID returns a new unique ObjectID.

func NewObjectIDWithHexString

func NewObjectIDWithHexString(s string) (o ObjectID, err error)

func NewObjectIDWithTime

func NewObjectIDWithTime(t time.Time) ObjectID

NewObjectIDWithTime returns a dummy ObjectID with the timestamp part filled with the provided number of seconds from epoch UTC, and all other parts filled with zeroes. It's not safe to insert a document with an id generated by this method, it is useful only for queries to find documents with ids generated before or after the specified timestamp.

func (ObjectID) Counter

func (id ObjectID) Counter() int32

Counter returns the incrementing value part of the id. It's a runtime error to call this method with an invalid id.

func (ObjectID) Hex

func (id ObjectID) Hex() string

Hex returns a hex representation of the ObjectID.

func (ObjectID) Machine

func (id ObjectID) Machine() []byte

Machine returns the 3-byte machine id part of the id. It's a runtime error to call this method with an invalid id.

func (ObjectID) Pid

func (id ObjectID) Pid() uint16

Pid returns the process id part of the id. It's a runtime error to call this method with an invalid id.

func (ObjectID) Time

func (id ObjectID) Time() time.Time

Time returns the timestamp part of the id. It's a runtime error to call this method with an invalid id.

Directories

Path Synopsis
zap
rpc

Jump to

Keyboard shortcuts

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