diff options
| author | Jonathan Amsterdam <jba@google.com> | 2020-05-20 15:06:38 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2020-05-21 16:07:40 +0000 |
| commit | 78e81b4117e52245be42ddc9524901bdbb93048b (patch) | |
| tree | d6e9436aed54c0407f78b4266878784ac5494a07 /internal/database/database.go | |
| parent | 29e65a82241d72d43b809eb5f76f85aaa7777627 (diff) | |
| download | go-x-pkgsite-78e81b4117e52245be42ddc9524901bdbb93048b.tar.xz | |
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>
Diffstat (limited to 'internal/database/database.go')
| -rw-r--r-- | internal/database/database.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/internal/database/database.go b/internal/database/database.go index 39431740..f1009b35 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -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) } } |
