forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_helpers.go
32 lines (27 loc) · 719 Bytes
/
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
package main
import (
"net/http"
"github.com/Sirupsen/logrus"
"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": requestIP(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)
}