Ejemplo n.º 1
0
// DefaultAfter is the default func assigned to *Middleware.After
func DefaultAfter(entry *logrus.Entry, res negroni.ResponseWriter, latency time.Duration, name string) *logrus.Entry {
	return entry.WithFields(logrus.Fields{
		"status":      res.Status(),
		"text_status": http.StatusText(res.Status()),
		"took":        latency,
		fmt.Sprintf("measure#%s.latency", name): latency.Nanoseconds(),
	})
}
Ejemplo n.º 2
0
func customAfter(entry *logrus.Entry, res negroni.ResponseWriter, latency time.Duration, name string) *logrus.Entry {
	fields := logrus.Fields{
		"ALL_DONE":        true,
		"RESPONSE_STATUS": res.Status(),

		fmt.Sprintf("%s_LATENCY", strings.ToUpper(name)): latency,
	}

	// one way to replace an existing entry key
	if requestId, ok := entry.Data["request_id"]; ok {
		fields["REQUEST_ID"] = requestId
		delete(entry.Data, "request_id")
	}

	return entry.WithFields(fields)
}