Task #26343
Implement logging for web service start and stop events
Start date:
24/03/2025
Due date:
% Done:
100%
Estimated time:
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.
Updated by Shuvam Misra 7 months ago
Actually, I'd prefer one log entry, not two, at the end of each WS call, logging details about the call plus the duration.
Updated by Sachin Divekar 6 months ago
- % 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"`
}