Documentation
¶
Index ¶
Constants ¶
View Source
const (
// ResultSuccess 表示成功执行 SQL 的结果标记
ResultSuccess = "success"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Config 复用 gorm 内置 logger.Config(包含 SlowThreshold/LogLevel/Colorful 等)
loger.Config
// Console 只控制控制台输出,不关闭符合日志级别的 OTel SQL 日志。
Console bool
// Database 是 SQL 日志使用的数据库名称。
Database string
// DatabaseType 是与连接配置一致的数据库类型枚举。
DatabaseType uint32
}
Config 为自定义 gorm logger 的配置
type LogIdentity ¶ added in v1.0.3
type LogIdentity struct {
// UserId 是已验证的用户标识,没有用户上下文时为空。
UserId string `json:"user_id"`
// AppId 是用户登录应用,不是服务调用主体应用。
AppId string `json:"app_id"`
// TenantId 是用户上下文所属租户,不要求与服务主体租户一致。
TenantId string `json:"tenant_id"`
// ServiceAppId 来自当前服务的本地配置。
ServiceAppId string `json:"service_app_id"`
// ServiceInstanceId 来自当前服务实例的本地配置。
ServiceInstanceId string `json:"service_instance_id"`
}
LogIdentity 是框架接入层提供的最小可信身份投影,不含 session、凭证或请求入口。 ORM 不负责验证身份,也不从原始 metadata 建立或补齐身份。
type LogIdentityReader ¶ added in v1.0.3
type LogIdentityReader func(context.Context) LogIdentity
LogIdentityReader 从 SQL 执行上下文读取框架已验证的身份,由消费方显式适配。 未提供读取器时身份保持为空,不回退到原始 token、请求头或 metadata。
type OperationLogger ¶
type OperationLogger struct {
// Database 是当前连接使用的数据库名称。
Database string `json:"database"`
// Statement 是 GORM 回调提供的 SQL 文本;绑定参数不展开,但不清理已拼入的字面量。
Statement string `json:"statement"`
// Result 保留成功标记、慢 SQL 提示或数据库错误原文,不统一替换为固定错误字符串。
Result string `json:"result"`
// Path 是调用栈定位的代码文件与行号,不是 HTTP 或 gRPC 入口路径。
Path string `json:"path"`
// Duration 是 SQL 执行耗时,单位为微秒。
Duration uint64 `json:"duration"`
// Level 使用既有数值约定:1 为信息、2 为警告、3 为错误,0 表示其他级别。
Level uint32 `json:"level"`
// Type 是数据库类型枚举,不是日志类型或请求主体类型。
Type uint32 `json:"type"`
// TraceId 来自执行 SQL 时上下文中的有效 OTel span。
TraceId string `json:"trace_id"`
// ParentId 沿用既有日志字段名,实际记录当前 span ID,不解析其父 span。
ParentId string `json:"parent_id"`
// UserId 是可信读取器提供的用户标识,无用户身份时为空。
UserId string `json:"user_id"`
// AppId 是用户登录应用,不表示当前服务或上一跳服务。
AppId string `json:"app_id"`
// TenantId 是用户租户,不从请求头或服务主体推断。
TenantId string `json:"tenant_id"`
// ServiceAppId 是框架接入层提供的本地服务应用标识。
ServiceAppId string `json:"service_app_id"`
// ServiceInstanceId 是框架接入层提供的本地服务实例标识。
ServiceInstanceId string `json:"service_instance_id"`
}
OperationLogger 表示 SQL 操作日志,不复制完整请求上下文或身份凭证。
Click to show internal directories.
Click to hide internal directories.