Documentation
¶
Overview ¶
Example ¶
package main
import (
"github.com/tossp/tsgo/pkg/db"
"go.uber.org/zap"
"gorm.io/gorm"
)
func main() {
logger := db.NewLogger(zap.L())
logger.SetAsDefault() // optional: configure gorm to use this zapgorm.Logger for callbacks
db, _ := gorm.Open(nil, &gorm.Config{Logger: logger})
// do stuff normally
var _ = db // avoid "unused variable" warn
}
Index ¶
- Variables
- func AddGormTables(t ...interface{})
- func ColumnName(name string) string
- func DelAll() (err error)
- func G() *gorm.DB
- func IsRecordNotFoundError(err error) bool
- func Start() (err error)
- func TableName(name string) string
- type Logger
- func (l Logger) Error(ctx context.Context, str string, args ...interface{})
- func (l Logger) Info(ctx context.Context, str string, args ...interface{})
- func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (l Logger) SetAsDefault()
- func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l Logger) Warn(ctx context.Context, str string, args ...interface{})
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Expr = gorm.Expr
)
Functions ¶
func IsRecordNotFoundError ¶
IsRecordNotFoundError GORM实例
Types ¶
type Logger ¶
type Logger struct {
ZapLogger *zap.Logger
LogLevel gormlogger.LogLevel
SlowThreshold time.Duration
SkipCallerLookup bool
}
func (Logger) LogMode ¶
func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
func (Logger) SetAsDefault ¶
func (l Logger) SetAsDefault()
Click to show internal directories.
Click to hide internal directories.