-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
76 lines (57 loc) · 1.08 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package logp
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
)
//log
type Log struct {
f *os.File
}
//NewLog new
func NewLog() *Log {
l := &Log{}
return l
}
//Init ocsv
func (l *Log) Init(fname string) error {
// t := time.Now().Format("2006-01-02-15-04-05")
// t := time.Now().Unix()
// fname := strconv.FormatInt(t, 10)
f, err := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_APPEND, os.ModePerm)
if err != nil {
fmt.Println("crate log file error.")
return err
}
l.f = f
fmt.Println("loginit", f)
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(f)
log.SetLevel(log.DebugLevel)
return nil
}
func (l *Log) Info(msg string) error {
log.WithFields(log.Fields{
"animal": "stan",
"size": 10,
}).Info(msg)
return nil
}
func (l *Log) Debug(msg string) error {
log.WithFields(log.Fields{
"animal": "stan",
"size": 10,
}).Debug(msg)
return nil
}
func (l *Log) Error(msg string) error {
log.WithFields(log.Fields{
"animal": "stan",
"size": 10,
}).Error(msg)
return nil
}
func (l *Log) Close() error {
defer l.f.Close()
return nil
}