mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 14:13:52 +03:00
[FEAT] Don't log context cancelled SQL errors
- I found this while doing some unrelated testing in Forgejo. It wasn't my intention to log failed SQL queries if they were cancelled (which can happen quite frequently for larger instances) as in those cases it's not interesting to know which SQL query was run. My intentation was only to log an SQL query if there was an error reported by the database. - Ref #2140
This commit is contained in:
parent
c6a89b490d
commit
cbbcfdd400
1 changed files with 2 additions and 1 deletions
|
@ -7,6 +7,7 @@ package db
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -342,7 +343,7 @@ func (ErrorQueryHook) BeforeProcess(c *contexts.ContextHook) (context.Context, e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ErrorQueryHook) AfterProcess(c *contexts.ContextHook) error {
|
func (h *ErrorQueryHook) AfterProcess(c *contexts.ContextHook) error {
|
||||||
if c.Err != nil {
|
if c.Err != nil && !errors.Is(c.Err, context.Canceled) {
|
||||||
h.Logger.Log(8, log.ERROR, "[Error SQL Query] %s %v - %v", c.SQL, c.Args, c.Err)
|
h.Logger.Log(8, log.ERROR, "[Error SQL Query] %s %v - %v", c.SQL, c.Args, c.Err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue