smarter structured logs
This commit is contained in:
parent
1797bca311
commit
cd2ed76903
@ -20,7 +20,11 @@ func loggingMiddleware(w http.ResponseWriter, r *http.Request, next http.Handler
|
||||
start := time.Now()
|
||||
next(w, r)
|
||||
response := w.(negroni.ResponseWriter)
|
||||
utils.Logger.Debug().Str("FLY_REGION", flyRegion).Msgf("%s %s %d %s", r.Method, r.URL.Path, response.Status(), time.Since(start))
|
||||
logEvent := utils.Logger.Debug()
|
||||
if flyRegion != "" {
|
||||
logEvent.Str("FLY_REGION", flyRegion)
|
||||
}
|
||||
logEvent.Msgf("%s %s %d %s", r.Method, r.URL.Path, response.Status(), time.Since(start))
|
||||
}
|
||||
|
||||
func newHttpMux() http.Handler {
|
||||
|
12
xip/xip.go
12
xip/xip.go
@ -21,6 +21,7 @@ var (
|
||||
flyRegion = os.Getenv("FLY_REGION")
|
||||
dottedIpV4Regex = regexp.MustCompile(`(?:^|(?:[\w\d])+\.)(((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4})($|[.-])`)
|
||||
dashedIpV4Regex = regexp.MustCompile(`(?:^|(?:[\w\d])+\.)(((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\-?\b){4})($|[.-])`)
|
||||
anyWhitespaceRegex = regexp.MustCompile(`\s`)
|
||||
)
|
||||
|
||||
func (xip *Xip) SetTXTRecord(fqdn string, value string) {
|
||||
@ -333,10 +334,15 @@ func (xip *Xip) handleDnsRequest(response dns.ResponseWriter, request *dns.Msg)
|
||||
message.MsgHdr.Rcode = dns.RcodeRefused
|
||||
}
|
||||
|
||||
logEvent := utils.Logger.Debug().Str("FLY_REGION", flyRegion).Str("question", request.Question[0].String())
|
||||
re := regexp.MustCompile(`\s`)
|
||||
question := anyWhitespaceRegex.ReplaceAllString(request.Question[0].String(), " ")
|
||||
logEvent := utils.Logger.Debug().Str("question", question)
|
||||
if flyRegion != "" {
|
||||
logEvent.Str("FLY_REGION", flyRegion)
|
||||
}
|
||||
for i, answer := range message.Answer {
|
||||
logEvent.Str(fmt.Sprintf("answers[%d]", i), re.ReplaceAllString(answer.String(), " "))
|
||||
key := fmt.Sprintf("answers[%d]", i)
|
||||
value := anyWhitespaceRegex.ReplaceAllString(answer.String(), " ")
|
||||
logEvent.Str(key, value)
|
||||
}
|
||||
logEvent.Msg("resolved")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user