MCPcopy
hub / github.com/labstack/echo / RequestLoggerConfig

Struct RequestLoggerConfig

middleware/request_logger.go:124–186  ·  view source on GitHub ↗

Example for `slog` https://pkg.go.dev/log/slog logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ LogStatus: true, LogURI: true, HandleError: true, // forwards error to the global error handler, so it can de

Source from the content-addressed store, hash-verified

122
123// RequestLoggerConfig is configuration for Request Logger middleware.
124type RequestLoggerConfig struct {
125 // Skipper defines a function to skip middleware.
126 Skipper Skipper
127
128 // BeforeNextFunc defines a function that is called before next middleware or handler is called in chain.
129 BeforeNextFunc func(c *echo.Context)
130 // LogValuesFunc defines a function that is called with values extracted by logger from request/response.
131 // Mandatory.
132 LogValuesFunc func(c *echo.Context, v RequestLoggerValues) error
133
134 // HandleError instructs logger to call global error handler when next middleware/handler returns an error.
135 // This is useful when you have custom error handler that can decide to use different status codes.
136 //
137 // A side-effect of calling global error handler is that now Response has been committed and sent to the client
138 // and middlewares up in chain can not change Response status code or response body.
139 HandleError bool
140
141 // LogLatency instructs logger to record duration it took to execute rest of the handler chain (next(c) call).
142 LogLatency bool
143 // LogProtocol instructs logger to extract request protocol (i.e. `HTTP/1.1` or `HTTP/2`)
144 LogProtocol bool
145 // LogRemoteIP instructs logger to extract request remote IP. See `echo.Context.RealIP()` for implementation details.
146 LogRemoteIP bool
147 // LogHost instructs logger to extract request host value (i.e. `example.com`)
148 LogHost bool
149 // LogMethod instructs logger to extract request method value (i.e. `GET` etc)
150 LogMethod bool
151 // LogURI instructs logger to extract request URI (i.e. `/list?lang=en&page=1`)
152 LogURI bool
153 // LogURIPath instructs logger to extract request URI path part (i.e. `/list`)
154 LogURIPath bool
155 // LogRoutePath instructs logger to extract route path part to which request was matched to (i.e. `/user/:id`)
156 LogRoutePath bool
157 // LogRequestID instructs logger to extract request ID from request `X-Request-ID` header or response if request did not have value.
158 LogRequestID bool
159 // LogReferer instructs logger to extract request referer values.
160 LogReferer bool
161 // LogUserAgent instructs logger to extract request user agent values.
162 LogUserAgent bool
163 // LogStatus instructs logger to extract response status code. If handler chain returns an error,
164 // the status code is extracted from the error satisfying echo.StatusCoder interface.
165 LogStatus bool
166 // LogContentLength instructs logger to extract content length header value. Note: this value could be different from
167 // actual request body size as it could be spoofed etc.
168 LogContentLength bool
169 // LogResponseSize instructs logger to extract response content length value. Note: when used with Gzip middleware
170 // this value may not be always correct.
171 LogResponseSize bool
172 // LogHeaders instructs logger to extract given list of headers from request. Note: request can contain more than
173 // one header with same value so slice of values is been logger for each given header.
174 //
175 // Note: header values are converted to canonical form with http.CanonicalHeaderKey as this how request parser converts header
176 // names to. For example, the canonical key for "accept-encoding" is "Accept-Encoding".
177 LogHeaders []string
178 // LogQueryParams instructs logger to extract given list of query parameters from request URI. Note: request can
179 // contain more than one query parameter with same name so slice of values is been logger for each given query param name.
180 LogQueryParams []string
181 // LogFormValues instructs logger to extract given list of form values from request body+URI. Note: request can

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected