예제 #1
0
파일: http.go 프로젝트: bfirsh/dctx
// GetRequestLogger returns a logger that contains fields from the request in
// the current context. If the request is not available in the context, no
// fields will display. Request loggers can safely be pushed onto the context.
func GetRequestLogger(ctx dctx.Context) dctx.Logger {
	return dctx.GetLogger(ctx,
		"http.request.id",
		"http.request.method",
		"http.request.host",
		"http.request.uri",
		"http.request.referer",
		"http.request.useragent",
		"http.request.remoteaddr",
		"http.request.contenttype")
}
예제 #2
0
파일: http.go 프로젝트: bfirsh/dctx
// GetResponseLogger reads the current response stats and builds a logger.
// Because the values are read at call time, pushing a logger returned from
// this function on the context will lead to missing or invalid data. Only
// call this at the end of a request, after the response has been written.
func GetResponseLogger(ctx dctx.Context) dctx.Logger {
	l := dctx.GetLogger(ctx,
		"http.response.written",
		"http.response.status",
		"http.response.contenttype")

	duration := dctx.Since(ctx, "http.request.startedat")

	if duration > 0 {
		l = l.WithField("http.response.duration", duration.String())
	}

	return l
}