-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
47 lines (37 loc) · 899 Bytes
/
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
package xmpush
import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
)
type logger interface {
Debug(args ...interface{})
Debugf(format string, args ...interface{})
}
type nopeLogger struct{}
func (l *nopeLogger) Debug(args ...interface{}) {
// nope
}
func (l *nopeLogger) Debugf(format string, args ...interface{}) {
// nope
}
type simpleLogger struct {
log *log.Logger
}
func newSimpleLogger() *simpleLogger {
return &simpleLogger{
log: log.New(os.Stdout, "", log.LstdFlags),
}
}
func (l *simpleLogger) fileInfo() string {
_, file, line, _ := runtime.Caller(2)
return fmt.Sprintf("%s:%d", filepath.Base(file), line)
}
func (l *simpleLogger) Debug(args ...interface{}) {
l.log.Println("[debug]", l.fileInfo(), fmt.Sprint(args...))
}
func (l *simpleLogger) Debugf(format string, args ...interface{}) {
l.log.Println("[debug]", l.fileInfo(), fmt.Sprintf(format, args...))
}