log

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLoggerName = "default"

DefaultLoggerName 是默认的日志记录器名称 DefaultLoggerName is the default logger name

Variables

View Source
var LogEncodingConfig = zapcore.EncoderConfig{

	TimeKey: "time",

	LevelKey: "level",

	NameKey: "logger",

	CallerKey: "caller",

	FunctionKey: zapcore.OmitKey,

	MessageKey: "message",

	StacktraceKey: "stacktrace",

	LineEnding: zapcore.DefaultLineEnding,

	EncodeLevel: zapcore.CapitalLevelEncoder,

	EncodeTime: zapcore.ISO8601TimeEncoder,

	EncodeDuration: zapcore.StringDurationEncoder,

	EncodeCaller: zapcore.ShortCallerEncoder,

	NewReflectedEncoder: UseJSONReflectedEncoder,
}

LogEncodingConfig 表示日志编码配置 LogEncodingConfig represents the log encoding configuration

Functions

func UseJSONReflectedEncoder

func UseJSONReflectedEncoder(w io.Writer) zapcore.ReflectedEncoder

UseJSONReflectedEncoder 返回一个使用 json 解析器的 zapcore.ReflectedEncoder UseJSONReflectedEncoder returns a zapcore.ReflectedEncoder using json parser

Types

type LogEvent

type LogEvent struct {
	// Message 字段表示日志消息
	// The Message field represents the log message
	Message string `json:"message,omitempty" yaml:"message,omitempty"`

	// ID 字段表示事件的唯一标识符
	// The ID field represents the unique identifier of the event
	ID string `json:"id,omitempty" yaml:"id,omitempty"`

	// IP 字段表示发起请求的IP地址
	// The IP field represents the IP address of the request initiator
	IP string `json:"ip,omitempty" yaml:"ip,omitempty"`

	// EndPoint 字段表示请求的终端点
	// The EndPoint field represents the endpoint of the request
	EndPoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`

	// Path 字段表示请求的路径
	// The Path field represents the path of the request
	Path string `json:"path,omitempty" yaml:"path,omitempty"`

	// Method 字段表示请求的HTTP方法
	// The Method field represents the HTTP method of the request
	Method string `json:"method,omitempty" yaml:"method,omitempty"`

	// Code 字段表示响应的HTTP状态码
	// The Code field represents the HTTP status code of the response
	Code int `json:"statusCode,omitempty" yaml:"statusCode,omitempty"`

	// Status 字段表示请求的状态
	// The Status field represents the status of the request
	Status string `json:"status,omitempty" yaml:"status,omitempty"`

	// Latency 字段表示请求的延迟时间
	// The Latency field represents the latency of the request
	Latency string `json:"latency,omitempty" yaml:"latency,omitempty"`

	// Agent 字段表示发起请求的用户代理
	// The Agent field represents the user agent of the request initiator
	Agent string `json:"agent,omitempty" yaml:"agent,omitempty"`

	// ReqContentType 字段表示请求的内容类型
	// The ReqContentType field represents the content type of the request
	ReqContentType string `json:"reqContentType,omitempty" yaml:"reqContentType,omitempty"`

	// ReqQuery 字段表示请求的查询参数
	// The ReqQuery field represents the query parameters of the request
	ReqQuery string `json:"query,omitempty" yaml:"query,omitempty"`

	// ReqBody 字段表示请求的主体内容
	// The ReqBody field represents the body of the request
	ReqBody string `json:"reqBody,omitempty" yaml:"reqBody,omitempty"`

	// Error 字段表示请求中的任何错误
	// The Error field represents any errors in the request
	Error any `json:"error,omitempty" yaml:"error,omitempty"`

	// ErrorStack 字段表示错误的堆栈跟踪
	// The ErrorStack field represents the stack trace of the error
	ErrorStack string `json:"errorStack,omitempty" yaml:"errorStack,omitempty"`
}

LogEvent 结构体用于记录日志事件 The LogEvent struct is used to log events

func (*LogEvent) Reset

func (e *LogEvent) Reset()

Reset 是一个方法,用于重置 LogEvent 结构体的所有字段 Reset is a method used to reset all fields of the LogEvent struct

type Logger

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

Logger 结构体包装了 zap.Logger The Logger struct wraps zap.Logger

func NewLogger

func NewLogger(ws zapcore.WriteSyncer, opts ...zap.Option) *Logger

NewLogger 创建一个新的 Logger NewLogger creates a new Logger

func (*Logger) GetLogrLogger

func (l *Logger) GetLogrLogger() logr.Logger

GetLogrLogger 返回 logr.Logger GetLogrLogger returns the logr.Logger

func (*Logger) GetStdLogger

func (l *Logger) GetStdLogger() *log.Logger

GetStdLogger 返回标准库的 logger GetStdLogger returns the standard library logger

func (*Logger) GetZapLogger

func (l *Logger) GetZapLogger() *zap.Logger

GetZapLogger 返回 zap.Logger GetZapLogger returns the zap.Logger

func (*Logger) GetZapSugaredLogger

func (l *Logger) GetZapSugaredLogger() *zap.SugaredLogger

GetZapSugaredLogger 返回 zap.SugaredLogger GetZapSugaredLogger returns the zap.SugaredLogger

Jump to

Keyboard shortcuts

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