Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for including sql variables in debug statement #510

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading