Task #26343
Implement logging for web service start and stop events
Added by Sachin Divekar 3 months ago.
Updated about 1 month ago.
Description
Create a Gin middleware to log web service start and stop events. This middleware should log a "start" and "end" message for each web service call.
Actually, I'd prefer one log entry, not two, at the end of each WS call, logging details about the call plus the duration.
- Status changed from New to In Progress
- % Done changed from 0 to 100
Written a middleware that accepts a RequestLogger interface
type RequestLogger interface {
Log(info RequestInfo)
}
and logs request details. Basic testing is done by writing a sample program and sending requests. It logs the following:
type RequestInfo struct {
Method string `json:"method"`
Path string `json:"path"`
ClientIP string `json:"client_ip"`
StatusCode int `json:"status_code"`
Timestamp time.Time `json:"timestamp"` // When the request was received
Duration time.Duration `json:"duration"`
RequestSize int64 `json:"request_size"`
ResponseSize int64 `json:"response_size"`
Query string `json:"query,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
Referer string `json:"referer,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
}
- Status changed from In Progress to Testing
Also available in: Atom
PDF