зеркало из https://github.com/golang/pkgsite.git
internal/database: log isolation level
Change-Id: Ibd8d29e91b47e37419e5f76c122d6ac73f6989f9 Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/750957 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Julie Qiu <julieqiu@google.com>
This commit is contained in:
Родитель
29e65a8224
Коммит
78e81b4117
|
@ -187,7 +187,7 @@ func (db *DB) transact(ctx context.Context, opts *sql.TxOptions, txFunc func(*DB
|
|||
|
||||
dbtx := New(db.db)
|
||||
dbtx.tx = tx
|
||||
defer logTransaction(ctx)(&err)
|
||||
defer logTransaction(ctx, opts)(&err)
|
||||
if err := txFunc(dbtx); err != nil {
|
||||
return fmt.Errorf("txFunc(tx): %w", err)
|
||||
}
|
||||
|
@ -457,15 +457,20 @@ func logQuery(ctx context.Context, query string, args []interface{}) func(*error
|
|||
}
|
||||
}
|
||||
|
||||
func logTransaction(ctx context.Context) func(*error) {
|
||||
func logTransaction(ctx context.Context, opts *sql.TxOptions) func(*error) {
|
||||
if QueryLoggingDisabled {
|
||||
return func(*error) {}
|
||||
}
|
||||
uid := generateLoggingID()
|
||||
log.Debugf(ctx, "%s transaction started", uid)
|
||||
isoLevel := "default"
|
||||
if opts != nil {
|
||||
isoLevel = opts.Isolation.String()
|
||||
}
|
||||
log.Debugf(ctx, "%s transaction (isolation %s) started", uid, isoLevel)
|
||||
start := time.Now()
|
||||
return func(errp *error) {
|
||||
log.Debugf(ctx, "%s transaction finished in %s with error %v", uid, time.Since(start), *errp)
|
||||
log.Debugf(ctx, "%s transaction (isolation %s) finished in %s with error %v",
|
||||
uid, isoLevel, time.Since(start), *errp)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче