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
6b7491e1
Commit
6b7491e1
authored
Feb 01, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3903 from grafana/log-fixes
Log fixes
parents
2e20c680
fbc90e03
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
17 deletions
+36
-17
pkg/log/console.go
+5
-5
pkg/log/file.go
+2
-2
pkg/log/log.go
+28
-9
pkg/log/syslog.go
+1
-1
No files found.
pkg/log/console.go
View file @
6b7491e1
...
...
@@ -46,8 +46,8 @@ var (
// ConsoleWriter implements LoggerInterface and writes messages to terminal.
type
ConsoleWriter
struct
{
lg
*
log
.
Logger
Level
int
`json:"level"`
Formatting
bool
`json:"formatting"`
Level
LogLevel
`json:"level"`
Formatting
bool
`json:"formatting"`
}
// create ConsoleWriter returning as LoggerInterface.
...
...
@@ -63,7 +63,7 @@ func (cw *ConsoleWriter) Init(config string) error {
return
json
.
Unmarshal
([]
byte
(
config
),
cw
)
}
func
(
cw
*
ConsoleWriter
)
WriteMsg
(
msg
string
,
skip
,
level
int
)
error
{
func
(
cw
*
ConsoleWriter
)
WriteMsg
(
msg
string
,
skip
int
,
level
LogLevel
)
error
{
if
cw
.
Level
>
level
{
return
nil
}
...
...
@@ -82,11 +82,11 @@ func (_ *ConsoleWriter) Flush() {
func
(
_
*
ConsoleWriter
)
Destroy
()
{
}
func
printConsole
(
level
int
,
msg
string
)
{
func
printConsole
(
level
LogLevel
,
msg
string
)
{
consoleWriter
.
WriteMsg
(
msg
,
0
,
level
)
}
func
printfConsole
(
level
int
,
format
string
,
v
...
interface
{})
{
func
printfConsole
(
level
LogLevel
,
format
string
,
v
...
interface
{})
{
consoleWriter
.
WriteMsg
(
fmt
.
Sprintf
(
format
,
v
...
),
0
,
level
)
}
...
...
pkg/log/file.go
View file @
6b7491e1
...
...
@@ -41,7 +41,7 @@ type FileLogWriter struct {
startLock
sync
.
Mutex
// Only one log can write to the file
Level
int
`json:"level"`
Level
LogLevel
`json:"level"`
}
// an *os.File writer with locker.
...
...
@@ -132,7 +132,7 @@ func (w *FileLogWriter) docheck(size int) {
}
// write logger message into file.
func
(
w
*
FileLogWriter
)
WriteMsg
(
msg
string
,
skip
,
level
int
)
error
{
func
(
w
*
FileLogWriter
)
WriteMsg
(
msg
string
,
skip
int
,
level
LogLevel
)
error
{
if
level
<
w
.
Level
{
return
nil
}
...
...
pkg/log/log.go
View file @
6b7491e1
...
...
@@ -99,7 +99,7 @@ func Close() {
type
LogLevel
int
const
(
TRACE
=
iota
TRACE
LogLevel
=
iota
DEBUG
INFO
WARN
...
...
@@ -111,7 +111,7 @@ const (
// LoggerInterface represents behaviors of a logger provider.
type
LoggerInterface
interface
{
Init
(
config
string
)
error
WriteMsg
(
msg
string
,
skip
,
level
int
)
error
WriteMsg
(
msg
string
,
skip
int
,
level
LogLevel
)
error
Destroy
()
Flush
()
}
...
...
@@ -132,8 +132,9 @@ func Register(name string, log loggerType) {
}
type
logMsg
struct
{
skip
,
level
int
msg
string
skip
int
level
LogLevel
msg
string
}
// Logger is default logger in beego application.
...
...
@@ -141,7 +142,7 @@ type logMsg struct {
type
Logger
struct
{
adapter
string
lock
sync
.
Mutex
level
int
level
LogLevel
msg
chan
*
logMsg
outputs
map
[
string
]
LoggerInterface
quit
chan
bool
...
...
@@ -188,10 +189,7 @@ func (l *Logger) DelLogger(adapter string) error {
return
nil
}
func
(
l
*
Logger
)
writerMsg
(
skip
,
level
int
,
msg
string
)
error
{
if
l
.
level
>
level
{
return
nil
}
func
(
l
*
Logger
)
writerMsg
(
skip
int
,
level
LogLevel
,
msg
string
)
error
{
lm
:=
&
logMsg
{
skip
:
skip
,
level
:
level
,
...
...
@@ -266,36 +264,57 @@ func (l *Logger) Close() {
}
func
(
l
*
Logger
)
Trace
(
format
string
,
v
...
interface
{})
{
if
l
.
level
>
TRACE
{
return
}
msg
:=
fmt
.
Sprintf
(
"[T] "
+
format
,
v
...
)
l
.
writerMsg
(
0
,
TRACE
,
msg
)
}
func
(
l
*
Logger
)
Debug
(
format
string
,
v
...
interface
{})
{
if
l
.
level
>
DEBUG
{
return
}
msg
:=
fmt
.
Sprintf
(
"[D] "
+
format
,
v
...
)
l
.
writerMsg
(
0
,
DEBUG
,
msg
)
}
func
(
l
*
Logger
)
Info
(
format
string
,
v
...
interface
{})
{
if
l
.
level
>
INFO
{
return
}
msg
:=
fmt
.
Sprintf
(
"[I] "
+
format
,
v
...
)
l
.
writerMsg
(
0
,
INFO
,
msg
)
}
func
(
l
*
Logger
)
Warn
(
format
string
,
v
...
interface
{})
{
if
l
.
level
>
WARN
{
return
}
msg
:=
fmt
.
Sprintf
(
"[W] "
+
format
,
v
...
)
l
.
writerMsg
(
0
,
WARN
,
msg
)
}
func
(
l
*
Logger
)
Error
(
skip
int
,
format
string
,
v
...
interface
{})
{
if
l
.
level
>
ERROR
{
return
}
msg
:=
fmt
.
Sprintf
(
"[E] "
+
format
,
v
...
)
l
.
writerMsg
(
skip
,
ERROR
,
msg
)
}
func
(
l
*
Logger
)
Critical
(
skip
int
,
format
string
,
v
...
interface
{})
{
if
l
.
level
>
CRITICAL
{
return
}
msg
:=
fmt
.
Sprintf
(
"[C] "
+
format
,
v
...
)
l
.
writerMsg
(
skip
,
CRITICAL
,
msg
)
}
func
(
l
*
Logger
)
Fatal
(
skip
int
,
format
string
,
v
...
interface
{})
{
if
l
.
level
>
FATAL
{
return
}
msg
:=
fmt
.
Sprintf
(
"[F] "
+
format
,
v
...
)
l
.
writerMsg
(
skip
,
FATAL
,
msg
)
l
.
Close
()
...
...
pkg/log/syslog.go
View file @
6b7491e1
...
...
@@ -39,7 +39,7 @@ func (sw *SyslogWriter) Init(config string) error {
return
nil
}
func
(
sw
*
SyslogWriter
)
WriteMsg
(
msg
string
,
skip
,
level
int
)
error
{
func
(
sw
*
SyslogWriter
)
WriteMsg
(
msg
string
,
skip
int
,
level
LogLevel
)
error
{
var
err
error
switch
level
{
...
...
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