log/access.go
func Access(h http.Handler, opts ...Option) http.Handler {
	o := options{logger: handler.OutLogger(), dateFormat: AccessDateFormat}
	o.apply(opts)

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()

		wrapper := handler.NewResponseWrapper(w)

		uri := r.URL.RequestURI()
		remoteAddr := remoteAddr(r)
		remoteUser := remoteUser(r)
		method := r.Method
		referer := r.Header.Get("Referer")
		userAgent := r.Header.Get("User-Agent")

		h.ServeHTTP(wrapper, r)

		for k, v := range wrapper.Header() {
			w.Header()[k] = v
		}
		w.WriteHeader(wrapper.Code)
		w.Write(wrapper.Body.Bytes())

		now := time.Now()
		timestamp := now.Format(o.dateFormat)
		code := wrapper.Code
		length := wrapper.Body.Len()

		o.logger.Print(fmt.Sprintf("%s - %s [%s - %s] \"%s %s\" %d %d \"%s\" %s",
			remoteAddr, remoteUser, timestamp, now.Sub(start), method, uri, code, length, referer, userAgent))
	})
}
func Access(h http.Handler, opts ...Option) http.Handler {
	o := options{logger: handler.OutLogger(), dateFormat: AccessDateFormat}
	o.apply(opts)

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()

		wrapper := handler.NewResponseWrapper(w)

		uri := r.URL.RequestURI()
		remoteAddr := remoteAddr(r)
		remoteUser := remoteUser(r)
		method := r.Method
		referer := r.Header.Get("Referer")
		userAgent := r.Header.Get("User-Agent")

		h.ServeHTTP(wrapper, r)

		for k, v := range wrapper.Header() {
			w.Header()[k] = v
		}
		w.WriteHeader(wrapper.Code)
		w.Write(wrapper.Body.Bytes())

		now := time.Now()
		timestamp := now.Format(o.dateFormat)
		code := wrapper.Code
		length := wrapper.Body.Len()

		o.logger.Print(fmt.Sprintf("%s - %s [%s - %s] \"%s %s\" %d %d \"%s\" %s",
			remoteAddr, remoteUser, timestamp, now.Sub(start), method, uri, code, length, referer, userAgent))
	})
}
// Access returns a handler that writes an access log message to the provided
// logger, provided by the options, whenever the handler h is invoked. The log
// message is of the following format:
//
// IP - USER [DATETIME - DURATION] "HTTP_METHOD URI" STATUS_CODE BODY_LENGTH "REFERER" USER_AGENT
//
// By default, all messages are printed to os.Stdout.