Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
9f1c6a73
Commit
9f1c6a73
authored
Mar 06, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tech: added sql logger to log all sql statements sent to sql server
parent
6af62abd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
0 deletions
+126
-0
pkg/services/sqlstore/logger.go
+123
-0
pkg/services/sqlstore/sqlstore.go
+3
-0
No files found.
pkg/services/sqlstore/logger.go
0 → 100644
View file @
9f1c6a73
package
sqlstore
import
(
"fmt"
glog
"github.com/grafana/grafana/pkg/log"
"github.com/go-xorm/core"
)
type
XormLogger
struct
{
grafanaLog
glog
.
Logger
level
glog
.
Lvl
showSQL
bool
}
func
NewXormLogger
(
level
glog
.
Lvl
,
grafanaLog
glog
.
Logger
)
*
XormLogger
{
return
&
XormLogger
{
grafanaLog
:
grafanaLog
,
level
:
level
,
showSQL
:
true
,
}
}
// Error implement core.ILogger
func
(
s
*
XormLogger
)
Err
(
v
...
interface
{})
error
{
if
s
.
level
<=
glog
.
LvlError
{
s
.
grafanaLog
.
Error
(
fmt
.
Sprint
(
v
...
))
}
return
nil
}
// Errorf implement core.ILogger
func
(
s
*
XormLogger
)
Errf
(
format
string
,
v
...
interface
{})
error
{
if
s
.
level
<=
glog
.
LvlError
{
s
.
grafanaLog
.
Error
(
fmt
.
Sprintf
(
format
,
v
...
))
}
return
nil
}
// Debug implement core.ILogger
func
(
s
*
XormLogger
)
Debug
(
v
...
interface
{})
error
{
if
s
.
level
<=
glog
.
LvlDebug
{
s
.
grafanaLog
.
Debug
(
fmt
.
Sprint
(
v
...
))
}
return
nil
}
// Debugf implement core.ILogger
func
(
s
*
XormLogger
)
Debugf
(
format
string
,
v
...
interface
{})
error
{
if
s
.
level
<=
glog
.
LvlDebug
{
s
.
grafanaLog
.
Debug
(
fmt
.
Sprintf
(
format
,
v
...
))
}
return
nil
}
// Info implement core.ILogger
func
(
s
*
XormLogger
)
Info
(
v
...
interface
{})
error
{
if
s
.
level
<=
glog
.
LvlInfo
{
s
.
grafanaLog
.
Info
(
fmt
.
Sprint
(
v
...
))
}
return
nil
}
// Infof implement core.ILogger
func
(
s
*
XormLogger
)
Infof
(
format
string
,
v
...
interface
{})
error
{
if
s
.
level
<=
glog
.
LvlInfo
{
s
.
grafanaLog
.
Info
(
fmt
.
Sprintf
(
format
,
v
...
))
}
return
nil
}
// Warn implement core.ILogger
func
(
s
*
XormLogger
)
Warning
(
v
...
interface
{})
error
{
if
s
.
level
<=
glog
.
LvlWarn
{
s
.
grafanaLog
.
Warn
(
fmt
.
Sprint
(
v
...
))
}
return
nil
}
// Warnf implement core.ILogger
func
(
s
*
XormLogger
)
Warningf
(
format
string
,
v
...
interface
{})
error
{
if
s
.
level
<=
glog
.
LvlWarn
{
s
.
grafanaLog
.
Warn
(
fmt
.
Sprintf
(
format
,
v
...
))
}
return
nil
}
// Level implement core.ILogger
func
(
s
*
XormLogger
)
Level
()
core
.
LogLevel
{
switch
s
.
level
{
case
glog
.
LvlError
:
return
core
.
LOG_ERR
case
glog
.
LvlWarn
:
return
core
.
LOG_WARNING
case
glog
.
LvlInfo
:
return
core
.
LOG_INFO
case
glog
.
LvlDebug
:
return
core
.
LOG_DEBUG
default
:
return
core
.
LOG_ERR
}
}
// SetLevel implement core.ILogger
func
(
s
*
XormLogger
)
SetLevel
(
l
core
.
LogLevel
)
error
{
return
nil
}
// ShowSQL implement core.ILogger
func
(
s
*
XormLogger
)
ShowSQL
(
show
...
bool
)
{
s
.
grafanaLog
.
Error
(
"ShowSQL"
,
"show"
,
"show"
)
if
len
(
show
)
==
0
{
s
.
showSQL
=
true
return
}
s
.
showSQL
=
show
[
0
]
}
// IsShowSQL implement core.ILogger
func
(
s
*
XormLogger
)
IsShowSQL
()
bool
{
return
s
.
showSQL
}
pkg/services/sqlstore/sqlstore.go
View file @
9f1c6a73
...
...
@@ -160,6 +160,9 @@ func getEngine() (*xorm.Engine, error) {
engine
.
SetMaxConns
(
DbCfg
.
MaxConn
)
engine
.
SetMaxOpenConns
(
DbCfg
.
MaxOpenConn
)
engine
.
SetMaxIdleConns
(
DbCfg
.
MaxIdleConn
)
// engine.SetLogger(NewXormLogger(log.LvlInfo, log.New("sqlstore.xorm")))
// engine.ShowSQL = true
// engine.ShowInfo = true
}
return
engine
,
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment