logger

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ResultSuccess 表示成功执行 SQL 的结果标记
	ResultSuccess = "success"
)

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(config Config, userContextFields *UserContextFields) loger.Interface

NewLogger 构造一个 gorm logger,实现控制台输出与自定义回调输出

Types

type Config

type Config struct {
	// Config 复用 gorm 内置 logger.Config(包含 SlowThreshold/LogLevel/Colorful 等)
	loger.Config

	// 控制台是否输出日志
	Console bool
	// 数据库
	Database string
	// 数据库类型
	DatabaseType uint32
}

Config 为自定义 gorm logger 的配置

type OperationLogger

type OperationLogger struct {
	Database  string `json:"database"`
	Statement string `json:"statement"`
	Result    string `json:"result"`
	Path      string `json:"path"`

	Duration uint64 `json:"duration"`

	Level uint32 `json:"level"`
	Type  uint32 `json:"type"`

	TraceId  string `json:"trace_id"`
	ParentId string `json:"parent_id"`

	UserId   string `json:"user_id"`
	AppId    string `json:"app_id"`
	TenantId string `json:"tenant_id"`

	ServiceAppId      string `json:"service_app_id"`
	ServiceInstanceId string `json:"service_instance_id"`
}

OperationLogger 表示操作日志。

type UserContextFields

type UserContextFields struct {
	UserId            string `json:"user_id"`
	AppId             string `json:"app_id"`
	TenantId          string `json:"tenant_id"`
	OrgIds            string `json:"org_ids"`
	RoleIds           string `json:"role_ids"`
	ServiceAppId      string `json:"service_app_id"`
	ServiceInstanceId string `json:"service_instance_id"`
}

UserContextFields 为用户上下文字段,用于记录用户信息。

func (*UserContextFields) Normalize

func (u *UserContextFields) Normalize()

Normalize 为用户上下文字段设置默认值。

Jump to

Keyboard shortcuts

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