-
Notifications
You must be signed in to change notification settings - Fork 0
/
redislogger.go
51 lines (38 loc) · 1000 Bytes
/
redislogger.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
/*
* @Description:
* @Author: gphper
* @Date: 2021-08-22 15:03:08
*/
package newer
import (
"encoding/json"
"time"
globalRedis "github.com/kumataahh/eagle-eye/internal/redis"
"github.com/go-redis/redis"
)
type RedisLogger struct {
Client *redis.Client
Path string
}
func NewRedisLogger(path string) *RedisLogger {
return &RedisLogger{
Client: globalRedis.RedisClient,
Path: path,
}
}
func (logger *RedisLogger) Info(msg string, info map[string]string) {
info["level"] = "info"
info["msg"] = msg
info["ts"] = time.Now().String()
str, _ := json.Marshal(info)
time := time.Now().Format("20060102")
logger.Client.LPush("logs:"+time+":"+logger.Path+":info", string(str))
}
func (logger *RedisLogger) Error(msg string, info map[string]string) {
info["level"] = "error"
info["msg"] = msg
info["ts"] = time.Now().String()
str, _ := json.Marshal(info)
time := time.Now().Format("20060102")
logger.Client.LPush("logs:"+time+":"+logger.Path+":error", string(str))
}