Skip to content

Commit

Permalink
config: change enable-slow-log to boolean (pingcap#14864)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway authored Feb 20, 2020
1 parent 3cd5fb6 commit 6b09729
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ type Log struct {
// File log config.
File logutil.FileLogConfig `toml:"file" json:"file"`

EnableSlowLog bool `toml:"enable-slow-log" json:"enable-slow-log"`
SlowQueryFile string `toml:"slow-query-file" json:"slow-query-file"`
SlowThreshold uint64 `toml:"slow-threshold" json:"slow-threshold"`
ExpensiveThreshold uint `toml:"expensive-threshold" json:"expensive-threshold"`
QueryLogMaxLen uint64 `toml:"query-log-max-len" json:"query-log-max-len"`
EnableSlowLog uint32 `toml:"enable-slow-log" json:"enable-slow-log"`
RecordPlanInSlowLog uint32 `toml:"record-plan-in-slow-log" json:"record-plan-in-slow-log"`
}

Expand Down
3 changes: 3 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ format = "text"
# Enable annotating logs with the full stack error message, if not set, it will be defaulted to false.
# enable-error-stack = false

# Whether to enable slow query log.
enable-slow-log = true

# Stores slow query log into separated files.
slow-query-file = "tidb-slow.log"

Expand Down
4 changes: 2 additions & 2 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,8 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
level := log.GetLevel()
cfg := config.GetGlobalConfig()
costTime := time.Since(sessVars.StartTime) + sessVars.DurationParse
threshold := time.Duration(atomic.LoadUint64(&cfg.Log.SlowThreshold)) * time.Millisecond
enable := atomic.LoadUint32(&cfg.Log.EnableSlowLog) > 0
threshold := time.Duration(cfg.Log.SlowThreshold) * time.Millisecond
enable := cfg.Log.EnableSlowLog
// if the level is Debug, print slow logs anyway
if (!enable || costTime < threshold) && level > zapcore.DebugLevel {
return
Expand Down
2 changes: 1 addition & 1 deletion util/logutil/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const (
// DefaultRecordPlanInSlowLog is the default value for whether enable log query plan in the slow log.
DefaultRecordPlanInSlowLog = 1
// DefaultTiDBEnableSlowLog enables TiDB to log slow queries.
DefaultTiDBEnableSlowLog = 1
DefaultTiDBEnableSlowLog = true
)

// EmptyFileLogConfig is an empty FileLogConfig.
Expand Down

0 comments on commit 6b09729

Please sign in to comment.