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

executor: change to structured slow log for friendly JSON output #4657

Merged
merged 9 commits into from
Sep 29, 2017
9 changes: 7 additions & 2 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,15 @@ func (a *statement) logSlowQuery() {
sql = sql[:cfg.Log.QueryLogMaxLen] + fmt.Sprintf("(len:%d)", len(sql))
}
connID := a.ctx.GetSessionVars().ConnectionID
logEntry := log.WithFields(log.Fields{
"connectionId": connID,
"costTime": costTime,
"sql": sql,
})
if costTime < time.Duration(cfg.Log.SlowThreshold)*time.Millisecond {
log.Debugf("[%d][TIME_QUERY] %v %s", connID, costTime, sql)
logEntry.WithField("type", "query").Debugf("query")
} else {
log.Warnf("[%d][TIME_QUERY] %v %s", connID, costTime, sql)
logEntry.WithField("type", "slow-query").Warnf("slow-query")
}
}

Expand Down