Add request context data to db query logs
This commit is contained in:
parent
07c034bb75
commit
7b78ff5b6e
1 changed files with 8 additions and 14 deletions
22
db/db.go
22
db/db.go
|
@ -209,19 +209,11 @@ func (e *executor) execute(quit <-chan bool, send chan<- *Response) {
|
||||||
// and print the error to the log.
|
// and print the error to the log.
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if err := recover(); err != nil {
|
||||||
switch err := r.(type) {
|
stk := string(debug.Stack())
|
||||||
case string:
|
log.WithPrefix("db").WithFields(map[string]interface{}{
|
||||||
log.WithPrefix("db").Errorln(err)
|
"ctx": e.web, "stack": stk,
|
||||||
if log.Instance().Level >= log.DebugLevel {
|
}).Errorln(err)
|
||||||
log.WithPrefix("db").Debugf("%s", debug.Stack())
|
|
||||||
}
|
|
||||||
case error:
|
|
||||||
log.WithPrefix("db").Errorln(err)
|
|
||||||
if log.Instance().Level >= log.DebugLevel {
|
|
||||||
log.WithPrefix("db").WithError(err).Debugf("%s", debug.Stack())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -271,7 +263,9 @@ func (e *executor) execute(quit <-chan bool, send chan<- *Response) {
|
||||||
// query, along with the query execution
|
// query, along with the query execution
|
||||||
// speed, so we can analyse slow queries.
|
// speed, so we can analyse slow queries.
|
||||||
|
|
||||||
log.WithPrefix("sql").Debugln(stm)
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
||||||
|
"ctx": e.web,
|
||||||
|
}).Debugln(stm)
|
||||||
|
|
||||||
// Check to see if the current statement is
|
// Check to see if the current statement is
|
||||||
// a TRANSACTION statement, and if it is
|
// a TRANSACTION statement, and if it is
|
||||||
|
|
Loading…
Reference in a new issue