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
a02cf5be
Commit
a02cf5be
authored
Jun 07, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(logging): added loging filters
parent
3dc7706c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
17 deletions
+73
-17
conf/defaults.ini
+1
-4
conf/sample.ini
+0
-3
pkg/log/log.go
+62
-6
pkg/middleware/logger.go
+4
-3
pkg/services/sqlstore/migrator/migrator.go
+1
-1
pkg/setting/setting.go
+5
-0
No files found.
conf/defaults.ini
View file @
a02cf5be
...
...
@@ -248,12 +248,9 @@ templates_pattern = emails/*.html
#################################### Logging ##########################
[log]
# Either "console", "file", "syslog". Default is console and file
# Use
comma to separate multiple modes, e.g. "console,
file"
# Use
space to separate multiple modes, e.g. "console
file"
mode
=
console, file
# Buffer length of channel, keep it as it is if you don't know what it is.
buffer_len
=
10000
# Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Info"
level
=
Info
...
...
conf/sample.ini
View file @
a02cf5be
...
...
@@ -233,9 +233,6 @@ check_for_updates = true
# Use comma to separate multiple modes, e.g. "console, file"
;mode = console, file
# Buffer length of channel, keep it as it is if you don't know what it is.
;buffer_len = 10000
# Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Info"
;level = Info
...
...
pkg/log/log.go
View file @
a02cf5be
...
...
@@ -90,21 +90,40 @@ var logLevels = map[string]log15.Lvl{
"Critical"
:
log15
.
LvlCrit
,
}
func
getLogLevel
(
key
string
,
defaultName
string
,
cfg
*
ini
.
File
)
(
string
,
log15
.
Lvl
)
{
func
getLogLevel
FromConfig
(
key
string
,
defaultName
string
,
cfg
*
ini
.
File
)
(
string
,
log15
.
Lvl
)
{
levelName
:=
cfg
.
Section
(
key
)
.
Key
(
"level"
)
.
In
(
defaultName
,
[]
string
{
"Trace"
,
"Debug"
,
"Info"
,
"Warn"
,
"Error"
,
"Critical"
})
level
:=
getLogLevelFromString
(
levelName
)
return
levelName
,
level
}
func
getLogLevelFromString
(
levelName
string
)
log15
.
Lvl
{
level
,
ok
:=
logLevels
[
levelName
]
if
!
ok
{
Root
.
Error
(
"Unknown log level"
,
"level"
,
levelName
)
return
log15
.
LvlError
}
return
levelName
,
level
return
level
}
func
getFilters
(
filterStrArray
[]
string
)
map
[
string
]
log15
.
Lvl
{
filterMap
:=
make
(
map
[
string
]
log15
.
Lvl
)
for
_
,
filterStr
:=
range
filterStrArray
{
parts
:=
strings
.
Split
(
filterStr
,
":"
)
filterMap
[
parts
[
0
]]
=
getLogLevelFromString
(
parts
[
1
])
}
return
filterMap
}
func
ReadLoggingConfig
(
modes
[]
string
,
logsPath
string
,
cfg
*
ini
.
File
)
{
Close
()
defaultLevelName
,
_
:=
getLogLevel
(
"log"
,
"Info"
,
cfg
)
defaultLevelName
,
_
:=
getLogLevelFromConfig
(
"log"
,
"Info"
,
cfg
)
defaultFilters
:=
getFilters
(
cfg
.
Section
(
"log"
)
.
Key
(
"filters"
)
.
Strings
(
" "
))
handlers
:=
make
([]
log15
.
Handler
,
0
)
for
_
,
mode
:=
range
modes
{
...
...
@@ -115,12 +134,15 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) {
}
// Log level.
_
,
level
:=
getLogLevel
(
"log."
+
mode
,
defaultLevelName
,
cfg
)
_
,
level
:=
getLogLevelFromConfig
(
"log."
+
mode
,
defaultLevelName
,
cfg
)
modeFilters
:=
getFilters
(
sec
.
Key
(
"filters"
)
.
Strings
(
" "
))
var
handler
log15
.
Handler
// Generate log configuration.
switch
mode
{
case
"console"
:
handler
s
=
append
(
handlers
,
log15
.
LvlFilterHandler
(
level
,
log15
.
StdoutHandler
))
handler
=
log15
.
StdoutHandler
case
"file"
:
fileName
:=
sec
.
Key
(
"file_name"
)
.
MustString
(
filepath
.
Join
(
logsPath
,
"grafana.log"
))
os
.
MkdirAll
(
filepath
.
Dir
(
fileName
),
os
.
ModePerm
)
...
...
@@ -134,7 +156,7 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) {
fileHandler
.
Init
()
loggersToClose
=
append
(
loggersToClose
,
fileHandler
)
handler
s
=
append
(
handlers
,
log15
.
LvlFilterHandler
(
level
,
fileHandler
))
handler
=
fileHandler
// case "conn":
// LogConfigs[i] = util.DynMap{
...
...
@@ -168,7 +190,41 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) {
// "tag": sec.Key("tag").MustString(""),
// }
}
for
key
,
value
:=
range
defaultFilters
{
if
_
,
exist
:=
modeFilters
[
key
];
!
exist
{
modeFilters
[
key
]
=
value
}
}
for
key
,
value
:=
range
modeFilters
{
fmt
.
Printf
(
"key: %v, value: %v
\n
"
,
key
,
value
)
}
handler
=
LogFilterHandler
(
level
,
modeFilters
,
handler
)
handlers
=
append
(
handlers
,
handler
)
}
Root
.
SetHandler
(
log15
.
MultiHandler
(
handlers
...
))
}
func
LogFilterHandler
(
maxLevel
log15
.
Lvl
,
filters
map
[
string
]
log15
.
Lvl
,
h
log15
.
Handler
)
log15
.
Handler
{
return
log15
.
FilterHandler
(
func
(
r
*
log15
.
Record
)
(
pass
bool
)
{
if
len
(
filters
)
>
0
{
for
i
:=
0
;
i
<
len
(
r
.
Ctx
);
i
+=
2
{
key
:=
r
.
Ctx
[
i
]
.
(
string
)
if
key
==
"logger"
{
loggerName
,
strOk
:=
r
.
Ctx
[
i
+
1
]
.
(
string
)
if
strOk
{
if
filterLevel
,
ok
:=
filters
[
loggerName
];
ok
{
return
r
.
Lvl
<=
filterLevel
}
}
}
}
}
return
r
.
Lvl
<=
maxLevel
},
h
)
}
pkg/middleware/logger.go
View file @
a02cf5be
...
...
@@ -20,6 +20,7 @@ import (
"time"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/setting"
"gopkg.in/macaron.v1"
)
...
...
@@ -40,9 +41,9 @@ func Logger() macaron.Handler {
status
:=
rw
.
Status
()
if
status
==
200
||
status
==
304
{
//
if !setting.RouterLogging {
//
return
//
}
if
!
setting
.
RouterLogging
{
return
}
}
if
ctx
,
ok
:=
c
.
Data
[
"ctx"
];
ok
{
...
...
pkg/services/sqlstore/migrator/migrator.go
View file @
a02cf5be
...
...
@@ -29,7 +29,7 @@ type MigrationLog struct {
func
NewMigrator
(
engine
*
xorm
.
Engine
)
*
Migrator
{
mg
:=
&
Migrator
{}
mg
.
x
=
engine
mg
.
Logger
=
log
.
New
(
"
M
igrator"
)
mg
.
Logger
=
log
.
New
(
"
m
igrator"
)
mg
.
migrations
=
make
([]
Migration
,
0
)
mg
.
dialect
=
NewDialect
(
mg
.
x
.
DriverName
())
return
mg
...
...
pkg/setting/setting.go
View file @
a02cf5be
...
...
@@ -546,7 +546,12 @@ func readSessionConfig() {
}
func
initLogging
()
{
// split on comma
LogModes
=
strings
.
Split
(
Cfg
.
Section
(
"log"
)
.
Key
(
"mode"
)
.
MustString
(
"console"
),
","
)
// also try space
if
len
(
LogModes
)
==
1
{
LogModes
=
strings
.
Split
(
Cfg
.
Section
(
"log"
)
.
Key
(
"mode"
)
.
MustString
(
"console"
),
" "
)
}
LogsPath
=
makeAbsolute
(
Cfg
.
Section
(
"paths"
)
.
Key
(
"logs"
)
.
String
(),
HomePath
)
log
.
ReadLoggingConfig
(
LogModes
,
LogsPath
,
Cfg
)
}
...
...
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