Skip to content

Commit 644b6ba

Browse files
committed
增强 OracleDB 插件的 SQL 执行日志记录,添加错误处理日志以提高故障排查能力
1 parent 9477700 commit 644b6ba

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/plugins/oracledb_plugin.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ func (p *OracleDBPlugin) GetConnection(body *Body) (*sql.DB, error) {
3838
func (p *OracleDBPlugin) DoSQLExecute(body *Body) (qr *QueryResult) {
3939
startTime := time.Now()
4040
defer func() {
41-
logger.Log1.WithField("cost", time.Since(startTime).String()).Infof("SQL查询结束")
41+
if qr != nil && qr.Message != "success" {
42+
logger.Log1.WithField("cost", time.Since(startTime).String()).Errorf("SQL查询结束")
43+
} else {
44+
logger.Log1.WithField("cost", time.Since(startTime).String()).Infof("SQL查询结束")
45+
}
4246
}()
4347

4448
// 获取数据库连接
4549
db, err := p.GetConnection(body)
4650
if err != nil {
51+
logger.Log1.WithField("error", err).Error("获取数据库连接失败")
4752
return &QueryResult{
4853
Result: nil,
4954
Columns: nil,
@@ -57,6 +62,7 @@ func (p *OracleDBPlugin) DoSQLExecute(body *Body) (qr *QueryResult) {
5762

5863
rows, err := db.Query(body.SQL)
5964
if err != nil {
65+
logger.Log1.WithField("error", err).Error("执行SQL失败")
6066
return &QueryResult{
6167
Result: nil,
6268
Columns: nil,
@@ -68,6 +74,7 @@ func (p *OracleDBPlugin) DoSQLExecute(body *Body) (qr *QueryResult) {
6874
// 获取列名
6975
columns, err := rows.Columns()
7076
if err != nil {
77+
logger.Log1.WithField("error", err).Error("获取列名失败")
7178
return &QueryResult{
7279
Result: nil,
7380
Columns: nil,
@@ -78,6 +85,7 @@ func (p *OracleDBPlugin) DoSQLExecute(body *Body) (qr *QueryResult) {
7885
// 获取列的类型信息
7986
columnTypes, err := rows.ColumnTypes()
8087
if err != nil {
88+
logger.Log1.WithField("error", err).Error("获取列类型失败")
8189
return &QueryResult{
8290
Result: nil,
8391
Columns: nil,

0 commit comments

Comments
 (0)