We've implemented a comprehensive logging system to provide more insight into the application's behavior. This document explains the enhanced logging configuration and how to use it.
The enhanced logging configuration includes:
-
Detailed HTTP Request/Response Logging
- HTTP method, path, status code, and latency
- Request headers (Content-Type, User-Agent)
- Client IP address
- Response body (truncated for large responses)
- Error details if any
-
API Request/Response Body Logging
- Complete request bodies for all API endpoints
- Response bodies (truncated if over 1000 characters)
- Status codes for all responses
-
Panic Recovery and Stack Traces
- Automatic recovery from panics
- Full stack traces for debugging
- Detailed error reporting
-
File-based Logging
- All logs stored in
logs/http.log - Logs also displayed in the console
- All logs stored in
The main HTTP log format includes:
${time} | ${status} | ${latency} | ${method} ${path} | ${ip} | ${reqHeader:Content-Type} | ${reqHeader:User-Agent} | ${resBody} | ${error}
For API requests, an additional format is used:
REQUEST BODY [METHOD PATH]: JSON content
RESPONSE BODY [METHOD PATH] [Status: CODE]: JSON response
All logs are printed to the console while the server is running.
Logs are also written to logs/http.log in the project root directory. You can view these logs with:
cat logs/http.log # View entire log
tail -f logs/http.log # Follow log in real-time
grep ERROR logs/http.log # Find error entriesA typical API request will generate multiple log entries:
- Initial HTTP request log entry with method, path, and headers
- REQUEST BODY log entry showing what was sent to the server
- RESPONSE BODY log entry showing what was returned
- Final HTTP request log with status code and latency
When troubleshooting issues:
- Look for non-200 status codes in the logs
- Check request and response bodies for validation issues
- Search for ERROR or PANIC entries
- Examine stack traces for the source of any errors
For interactions with the Congress.gov API, examine the request and response logs to see:
- Which endpoints are being called
- What parameters are being sent
- The response data received
- Any errors in the API interactions
You can trace the full conversation flow with the LLM by examining:
- The request body sent to
/api/chat(user's message) - The behind-the-scenes API planning and interpretation steps
- The final response returned to the user
To further customize the logging configuration, you can:
- Modify the
Formatstring in the logger configuration - Adjust the log output destination (file or console)
- Change what types of requests or responses are logged
- Add more middleware for additional logging capabilities
See the Fiber Logger documentation for more options.