-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
67 lines (59 loc) · 1.24 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package floridalist
import(
"log"
"os"
"strings"
"strconv"
"github.com/comail/colog"
)
const TAB string = "\t"
type HttpLogger interface {
Write(host string, method string, uri string, status int, ua string)
}
type DefLogger struct {
DebugMode bool
}
func NewHttpLogger(c Config) HttpLogger {
l := new(DefLogger)
l.DebugMode = c.DebugMode
return l
}
func (l *DefLogger) Write(host string, method string, uri string, status int, ua string) {
msg := []string{
"host:", host,
TAB,
"method:", method,
TAB,
"uri:", uri,
TAB,
"status:", strconv.Itoa(status),
TAB,
"ua:", ua,
}
m := strings.Join(msg, "")
if l.DebugMode {
log.Printf("debug: %s", m)
} else {
log.Printf("info: %s", m)
}
}
type MemberLogger struct {
c *colog.CoLog
}
func NewMemberLogger(config Config) *MemberLogger {
c := colog.NewCoLog(os.Stdout, "member ", log.Ldate | log.Ltime | log.Lshortfile)
c.SetDefaultLevel(colog.LDebug)
c.SetMinLevel(colog.LInfo)
if config.DebugMode {
c.SetMinLevel(colog.LDebug)
if config.VerboseMode {
c.SetMinLevel(colog.LTrace)
}
}
ml := new(MemberLogger)
ml.c = c
return ml
}
func (ml *MemberLogger) NewLogger() *log.Logger {
return ml.c.NewLogger()
}