Use stack trace context in XORM trace logger (#43780)
* add caller and stack Valuer functions * Add WithPrefix and WithSuffix similar to what go-kit offers * replace New with just `with`. Remove filter wrapper because the first argument of the context argument is not logger but additional context. * update Xorm logger to use custom depth to display the datastore code instead of xorm
This commit is contained in:
@@ -12,6 +12,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/fs"
|
||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||
@@ -25,8 +28,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
_ "github.com/lib/pq"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -372,7 +373,8 @@ func (ss *SQLStore) initEngine(engine *xorm.Engine) error {
|
||||
if !debugSQL {
|
||||
engine.SetLogger(&xorm.DiscardLogger{})
|
||||
} else {
|
||||
engine.SetLogger(NewXormLogger(log.LvlInfo, log.New("sqlstore.xorm")))
|
||||
// add stack to database calls to be able to see what repository initiated queries. Top 7 items from the stack as they are likely in the xorm library.
|
||||
engine.SetLogger(NewXormLogger(log.LvlInfo, log.WithSuffix(log.New("sqlstore.xorm"), log.CallerContextKey, log.StackCaller(log.DefaultCallerDepth))))
|
||||
engine.ShowSQL(true)
|
||||
engine.ShowExecTime(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user