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

config: change enable-slow-log to boolean #14864

Merged
merged 3 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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"`
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
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