forked from azer/logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
50 lines (42 loc) · 1.04 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package logger
import (
"fmt"
)
// New returns a logger bound to the given name.
func New(name string) *Logger {
return &Logger{
Name: name,
}
}
// Logger is the unit of the logger package, a smart, pretty-printing gate between
// the program and the output stream.
type Logger struct {
// Name by which the logger is identified when enabling or disabling it, and by envvar.
Name string
}
func (logger *Logger) Log(level, message string, args []interface{}) {
v, attrs := SplitAttrs(args)
runtime.Log(&Log{
Package: logger.Name,
Level: level,
Message: fmt.Sprintf(message, v...),
Time: Now(),
Attrs: attrs,
})
}
// Info prints log information to the screen that is informational in nature.
func (l *Logger) Info(msg string, v ...interface{}) {
l.Log("INFO", msg, v)
}
// Error logs an error message.
func (l *Logger) Error(msg string, v ...interface{}) {
l.Log("ERROR", msg, v)
}
// Timer returns a timer sub-logger.
func (l *Logger) Timer() *Log {
return &Log{
Package: l.Name,
Level: "TIMER",
Time: Now(),
}
}