mirror of https://github.com/jackc/pgx.git
feat: add time duration to error query and copy
parent
8b9b4055f3
commit
bfb19cd4f6
|
@ -153,13 +153,13 @@ func (ct *copyFrom) run(ctx context.Context) (int64, error) {
|
||||||
<-doneChan
|
<-doneChan
|
||||||
|
|
||||||
rowsAffected := commandTag.RowsAffected()
|
rowsAffected := commandTag.RowsAffected()
|
||||||
|
endTime := time.Now()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if ct.conn.shouldLog(LogLevelInfo) {
|
if ct.conn.shouldLog(LogLevelInfo) {
|
||||||
endTime := time.Now()
|
|
||||||
ct.conn.log(ctx, LogLevelInfo, "CopyFrom", map[string]interface{}{"tableName": ct.tableName, "columnNames": ct.columnNames, "time": endTime.Sub(startTime), "rowCount": rowsAffected})
|
ct.conn.log(ctx, LogLevelInfo, "CopyFrom", map[string]interface{}{"tableName": ct.tableName, "columnNames": ct.columnNames, "time": endTime.Sub(startTime), "rowCount": rowsAffected})
|
||||||
}
|
}
|
||||||
} else if ct.conn.shouldLog(LogLevelError) {
|
} else if ct.conn.shouldLog(LogLevelError) {
|
||||||
ct.conn.log(ctx, LogLevelError, "CopyFrom", map[string]interface{}{"err": err, "tableName": ct.tableName, "columnNames": ct.columnNames})
|
ct.conn.log(ctx, LogLevelError, "CopyFrom", map[string]interface{}{"err": err, "tableName": ct.tableName, "columnNames": ct.columnNames, "time": endTime.Sub(startTime)})
|
||||||
}
|
}
|
||||||
|
|
||||||
return rowsAffected, err
|
return rowsAffected, err
|
||||||
|
|
5
rows.go
5
rows.go
|
@ -143,14 +143,15 @@ func (rows *connRows) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows.logger != nil {
|
if rows.logger != nil {
|
||||||
|
endTime := time.Now()
|
||||||
|
|
||||||
if rows.err == nil {
|
if rows.err == nil {
|
||||||
if rows.logger.shouldLog(LogLevelInfo) {
|
if rows.logger.shouldLog(LogLevelInfo) {
|
||||||
endTime := time.Now()
|
|
||||||
rows.logger.log(rows.ctx, LogLevelInfo, "Query", map[string]interface{}{"sql": rows.sql, "args": logQueryArgs(rows.args), "time": endTime.Sub(rows.startTime), "rowCount": rows.rowCount})
|
rows.logger.log(rows.ctx, LogLevelInfo, "Query", map[string]interface{}{"sql": rows.sql, "args": logQueryArgs(rows.args), "time": endTime.Sub(rows.startTime), "rowCount": rows.rowCount})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if rows.logger.shouldLog(LogLevelError) {
|
if rows.logger.shouldLog(LogLevelError) {
|
||||||
rows.logger.log(rows.ctx, LogLevelError, "Query", map[string]interface{}{"err": rows.err, "sql": rows.sql, "args": logQueryArgs(rows.args)})
|
rows.logger.log(rows.ctx, LogLevelError, "Query", map[string]interface{}{"err": rows.err, "sql": rows.sql, "time": endTime.Sub(rows.startTime), "args": logQueryArgs(rows.args)})
|
||||||
}
|
}
|
||||||
if rows.err != nil && rows.conn.stmtcache != nil {
|
if rows.err != nil && rows.conn.stmtcache != nil {
|
||||||
rows.conn.stmtcache.StatementErrored(rows.sql, rows.err)
|
rows.conn.stmtcache.StatementErrored(rows.sql, rows.err)
|
||||||
|
|
Loading…
Reference in New Issue