Skip to content

Commit

Permalink
Fix: Added support for including sql variables in debug statement (#510)
Browse files Browse the repository at this point in the history
* Added support for including sql variables in debug statement
* replaced in-line variable replacement

Authored-by: Abdurrahman Dridi <[email protected]>
  • Loading branch information
AbdulDridi authored May 21, 2024
1 parent 10b5161 commit 81c06b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ type Config struct {
// Log warnings and other debug information
Debug bool `jsonschema:"title=Debug,default=false"`

// Log SQL Query variable values
LogSQLVars bool `mapstructure:"log_sql_vars" json:"log_sql_vars" yaml:"log_sql_vars" jsonschema:"title=Log SQL Variables,default=false"`

// Database polling duration (in seconds) used by subscriptions to
// query for updates.
SubsPollDuration time.Duration `mapstructure:"subs_poll_duration" json:"subs_poll_duration" yaml:"subs_poll_duration" jsonschema:"title=Subscription Polling Duration,default=5s"`
Expand Down
9 changes: 9 additions & 0 deletions serv/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ func (s *service) reqLog(res *core.Result, rc core.ReqConfig, resTimeMs int64, e
fields = append(fields, zap.String("namespace", ns))
}

if res.Vars != nil && s.conf.Core.LogSQLVars {
var vars map[string]interface{}
err := json.Unmarshal(res.Vars, &vars)
if err != nil {
s.log.Error("failed to unmarshal sql vars", zap.Error(err))
}
fields = append(fields, zap.Any("sqlVars", vars))
}

if sql != "" && s.logLevel >= logLevelDebug {
fields = append(fields, zap.String("sql", sql))
}
Expand Down

0 comments on commit 81c06b9

Please sign in to comment.