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.Debugf("query")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change TIME_QUERY to query ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it actually logs all queries, not just for slow queries.

} else {
log.Warnf("[%d][TIME_QUERY] %v %s", connID, costTime, sql)
logEntry.Infof("slow-query")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Warnf?

}
}

Expand Down