Skip to content

Commit

Permalink
Merge pull request #138 from taosdata/feat/TD-31615
Browse files Browse the repository at this point in the history
improve log
  • Loading branch information
sheyanjie-qq authored Sep 12, 2024
2 parents 4b36a8d + 14a2997 commit b36f98a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 0 additions & 4 deletions api/gen_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,6 @@ func (gm *GeneralMetric) initColumnSeqMap() error {
return err
}

if logger.Logger.IsLevelEnabled(logrus.TraceLevel) {
gmLogger.Tracef("data:%v", data)
}

if len(data.Data) < 1 || len(data.Data[0]) < 4 {
return fmt.Errorf("desc %s.%s error", gm.database, tableName)
}
Expand Down
19 changes: 18 additions & 1 deletion db/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package db
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -84,6 +85,20 @@ func (c *Connector) Exec(ctx context.Context, sql string, qid uint64) (int64, er
return res.RowsAffected()
}

func logData(data *Data, logger *logrus.Entry) {
if data == nil {
logger.Tracef("No data to display")
return
}

jsonData, err := json.Marshal(data)
if err != nil {
logger.Errorf("Failed to marshal data to JSON: %v", err)
return
}
logger.Tracef("%s", jsonData)
}

func (c *Connector) Query(ctx context.Context, sql string, qid uint64) (*Data, error) {
dbLogger = dbLogger.WithFields(logrus.Fields{config.ReqIDKey: qid})
ctx = context.WithValue(ctx, common.ReqIDKey, int64(qid))
Expand Down Expand Up @@ -132,7 +147,9 @@ func (c *Connector) Query(ctx context.Context, sql string, qid uint64) (*Data, e
data.Data = append(data.Data, tmp)
}

dbLogger.Tracef("get data:%v", data)
if dbLogger.Logger.IsLevelEnabled(logrus.TraceLevel) {
logData(data, dbLogger)
}
return data, nil
}

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var Name = fmt.Sprintf("%skeeper", version.CUS_PROMPT)

const ReqIDKey = "qid"
const ReqIDKey = "QID"
const ModelKey = "model"

type Config struct {
Expand Down

0 comments on commit b36f98a

Please sign in to comment.