forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_helpers.go
54 lines (47 loc) · 1.24 KB
/
log_helpers.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
package main
import (
"net/http"
"github.com/Sirupsen/logrus"
"github.com/TykTechnologies/tyk/request"
"github.com/TykTechnologies/tyk/config"
)
// identifies that field value was hidden before output to the log
const logHiddenValue = "<hidden>"
func getLogEntryForRequest(r *http.Request, key string, data map[string]interface{}) *logrus.Entry {
// populate http request fields
fields := logrus.Fields{
"path": r.URL.Path,
"origin": request.RealIP(r),
}
// add key to log if configured to do so
if key != "" {
fields["key"] = key
if !config.Global.EnableKeyLogging {
fields["key"] = logHiddenValue
}
}
// add to log additional fields if any passed
for key, val := range data {
fields[key] = val
}
return log.WithFields(fields)
}
func getExplicitLogEntryForRequest(path string, IP string, key string, data map[string]interface{}) *logrus.Entry {
// populate http request fields
fields := logrus.Fields{
"path": path,
"origin": IP,
}
// add key to log if configured to do so
if key != "" {
fields["key"] = key
if !config.Global.EnableKeyLogging {
fields["key"] = logHiddenValue
}
}
// add to log additional fields if any passed
for key, val := range data {
fields[key] = val
}
return log.WithFields(fields)
}