GoVisual can capture and log HTTP requests and responses passing through your application. This document explains how request logging works and how to configure it.
By default, GoVisual logs basic request and response metadata:
- HTTP method (GET, POST, PUT, etc.)
- URL path
- Query parameters
- Status code
- Response time
- Timestamp
- Request and response headers
This basic information is always captured and does not require any special configuration.
For more detailed logging, you can enable request and response body logging:
handler := govisual.Wrap(
mux,
govisual.WithRequestBodyLogging(true), // Log request bodies
govisual.WithResponseBodyLogging(true), // Log response bodies
)When enabling body logging, keep in mind:
- Performance Impact: Logging bodies requires reading them completely into memory, which may impact performance for large payloads
- Security Concerns: Request and response bodies may contain sensitive information (passwords, tokens, PII)
- Memory Usage: Bodies are stored in memory by default, which can increase memory usage
To prevent logging of certain paths (like health checks or static assets), use the WithIgnorePaths option:
handler := govisual.Wrap(
mux,
govisual.WithIgnorePaths(
"/health", // Exact match
"/metrics", // Exact match
"/static/*", // Wildcard pattern
"/api/auth/*" // Wildcard pattern
),
)The dashboard path (/__viz by default) is automatically ignored to prevent recursive logging.
How requests are stored depends on your configured storage backend:
- Memory Storage: Logs are kept in memory and lost when the application restarts
- PostgreSQL Storage: Logs are stored in a database table and persist across restarts
- Redis Storage: Logs are stored with a configurable time-to-live (TTL)
See Storage Backends for more details.
All headers are logged by default. If some headers contain sensitive information, you should handle them at the application level before they reach GoVisual.
Internally, GoVisual stores request logs with the following structure:
type RequestLog struct {
ID string // Unique identifier
Timestamp time.Time // When the request was received
Method string // HTTP method
Path string // URL path
Query string // Query parameters
RequestHeaders map[string][]string // Request headers
ResponseHeaders map[string][]string // Response headers
StatusCode int // HTTP status code
Duration time.Duration // Response time
RequestBody string // Request body (if enabled)
ResponseBody string // Response body (if enabled)
Error string // Error message (if any)
MiddlewareTrace []MiddlewareTraceEntry // Middleware execution trace
RouteTrace []RouteTraceEntry // Route matching trace
}A complete example of request logging configuration:
handler := govisual.Wrap(
mux,
govisual.WithRequestBodyLogging(true),
govisual.WithResponseBodyLogging(true),
govisual.WithIgnorePaths("/health", "/metrics", "/static/*"),
govisual.WithMaxRequests(1000),
)- Configuration Options - All available configuration options
- Storage Backends - Configure where logs are stored
- Middleware Tracing - How middleware tracing works