-
Notifications
You must be signed in to change notification settings - Fork 12
/
logrus.go
68 lines (63 loc) · 1.45 KB
/
logrus.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
package logrus_influxdb
import (
"fmt"
"net/http"
"strconv"
"github.com/sirupsen/logrus"
)
// Try to return a field from logrus
// Taken from Sentry adapter (from https://github.com/evalphobia/logrus_sentry)
func getTag(d logrus.Fields, key string) (tag string, ok bool) {
v, ok := d[key]
if !ok {
return "", false
}
switch vs := v.(type) {
case fmt.Stringer:
return vs.String(), true
case string:
return vs, true
case byte:
return string(vs), true
case int:
return strconv.FormatInt(int64(vs), 10), true
case int32:
return strconv.FormatInt(int64(vs), 10), true
case int64:
return strconv.FormatInt(vs, 10), true
case uint:
return strconv.FormatUint(uint64(vs), 10), true
case uint32:
return strconv.FormatUint(uint64(vs), 10), true
case uint64:
return strconv.FormatUint(vs, 10), true
default:
return "", false
}
return "", false
}
// Try to return an http request
// Taken from Sentry adapter (from https://github.com/evalphobia/logrus_sentry)
func getRequest(d logrus.Fields, key string) (req *http.Request, ok bool) {
v, ok := d[key]
if !ok {
return nil, false
}
req, ok = v.(*http.Request)
if !ok || req == nil {
return nil, false
}
return req, true
}
// Levels are the available logging levels.
func (hook *InfluxDBHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
logrus.InfoLevel,
logrus.DebugLevel,
logrus.TraceLevel,
}
}