My english is so poor, article translated with Google Translate. Form is nested in Gin. Because there is some chain information in gin context, I used WithContext(c) to pass the gin context.

func XXX(c *gin.Context, username string) *db2.User {
    ...
    result := db.XXXX.WithContext(c).Table(db.UserTable).Where("username = ?", username).Find(user)
    ....
}

I override Logger.Interface. But some methods of calling logs in the source code use context.Background(), like callback.go:194: p.db.Logger.Error(context.Background(), "Got error when compile callbacks, got %v", err). Printing the log needs to add the gin context at the same time. Will there be a type change exception in this type of writing?

type dblogger struct{}

func (d *dblogger) LogMode(level logger.LogLevel) logger.Interface {
    // 只会在单条debug调用,不重要
    return d
}
func (d *dblogger) Info(ctx context.Context, s string, i ...interface{}) {
    log.Info(ctx.(*gin.Context)).Msgf(s, i)
}
func (d *dblogger) Warn(ctx context.Context, s string, i ...interface{}) {
    log.Warn(ctx.(*gin.Context)).Msgf(s, i)
}
func (d *dblogger) Error(ctx context.Context, s string, i ...interface{}) {
    log.Error(ctx.(*gin.Context)).Msgf(s, i)
}
func (d *dblogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
    sql, rowsAffected := fc()
    log.Info(ctx.(*gin.Context)).
        Str("sql", sql).
        Int64("rowsAffected", rowsAffected).
        Str("begin", begin.Format(time.RFC3339)).
        Err(err).
        Send()
}

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking