Documentation
¶
Index ¶
- func GormLoggerFrom(logger kratoslog.Logger, module string) gormlogger.Interface
- type GormLogger
- func (l GormLogger) Error(ctx context.Context, str string, args ...any)
- func (l GormLogger) Info(ctx context.Context, str string, args ...any)
- func (l GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (l GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l GormLogger) Warn(ctx context.Context, str string, args ...any)
- type Helper
- type Logger
- type Option
- type ZapLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GormLoggerFrom ¶
func GormLoggerFrom(logger kratoslog.Logger, module string) gormlogger.Interface
Types ¶
type GormLogger ¶
GormLogger 操作对象,实现 gormlogger.Interface
func (GormLogger) Error ¶
func (l GormLogger) Error(ctx context.Context, str string, args ...any)
Error 实现 gormlogger.Interface 的 Error 方法
func (GormLogger) Info ¶
func (l GormLogger) Info(ctx context.Context, str string, args ...any)
Info 实现 gormlogger.Interface 的 Info 方法
func (GormLogger) LogMode ¶
func (l GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
LogMode 实现 gormlogger.Interface 的 LogMode 方法
type Helper ¶
func For ¶
For creates a *Helper scoped to the given module — the one-liner replacement for logger.NewHelper(l, logger.WithModule("x/y/z")).
Before: logger.NewHelper(l, logger.WithModule("user/biz/iam-service"))
After: logger.For(l, "user/biz/iam")
IMPORTANT: The returned helper is NOT bound to any context. Kratos Valuers (such as the trace_id / span_id valuers registered by bootstrap) are only invoked with the ctx attached to the helper at log-emit time. To make them resolve, callers MUST chain .WithContext(ctx) per call:
r.log.WithContext(ctx).Warnf("query failed: %v", err)
Calling helper methods directly (r.log.Warnf(...)) without .WithContext leaves context-derived fields blank. See ExampleHelper_WithContext.
func NewHelper ¶
NewHelper creates a *Helper with optional Option fields applied. Prefer For() when only a module label is needed.
IMPORTANT: As with For(), callers must chain .WithContext(ctx) at each call site to activate context-aware valuers (trace_id, span_id, etc). See ExampleHelper_WithContext for the canonical pattern.
type Option ¶
type Option func(keyvals *[]any)
Option is a function that appends key-value pairs to a logger's fields.
func WithModule ¶
WithModule returns an Option that adds a "module" field. Naming convention: "component/layer/service" (e.g. "user/biz/iam").
type ZapLogger ¶
type ZapLogger struct {
// contains filtered or unexported fields
}
ZapLogger wraps *zap.Logger and satisfies kratos log.Logger.
func New ¶
New creates a ZapLogger from a proto App config. nil-safe: returns a dev console logger when app is nil or app.Log is nil.
func (*ZapLogger) GetGormLogger ¶
func (l *ZapLogger) GetGormLogger(module string) GormLogger
GetGormLogger returns a GORM-compatible logger scoped to the given module.