-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
47 lines (42 loc) · 874 Bytes
/
log.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
package singularity
import (
"fmt"
"time"
)
//Log is used to log.
func (singularity *Singularity) Log(level int, message string, i ...interface{}) {
singularity.log(level, message, i...)
}
//SetLogger ...
func (singularity *Singularity) SetLogger(logger func(level int, message string, i ...interface{})) {
singularity.log = logger
}
//TODO Support passing a version of instance.
func defaultLogger(level int, message string, i ...interface{}) {
prefix := " ["
switch level {
case LogDebug:
prefix += "D"
case LogInfo:
prefix += "I"
case LogWarn:
prefix += "W"
case LogError:
prefix += "E"
case LogCrit:
prefix += "X"
default:
prefix += "?"
}
prefix += "] "
prefix += time.Now().Format(time.RFC3339) + " | "
fmt.Println(prefix + fmt.Sprintf(message, i...))
}
//Error Constants
const (
LogDebug = iota
LogInfo
LogWarn
LogError
LogCrit
)