Autostrada
Autostrada
Create a new codebase Get Autostrada Plus
Documentation Changelog Roadmap Give feedback
Login

DocumentationTraditional web application › Request logging

Request logging

If you select the Request logging option when generating your codebase, the cmd/web/middleware.go file will include a logRequest() middleware function.

This middleware logs information about every HTTP request received by the application, including the client IP address, request scheme, method, and URL path.

It also uses the MetricsResponseWriter type – defined in internal/response/metrics.go – to record the response status code and the number of bytes written in the response. This information is also included in the log entry for each request.

The output will look similar to these, depending on the logging format you selected when generating your codebase:

# Structured plaintext
time=2026-05-10T21:50:39.096+02:00 level=INFO msg="request completed" user.ip=127.0.0.1 request.method=GET request.url=/ request.proto=HTTP/1.1 response.status=200 response.size=697

# Colorized plaintext
May 10 21:51:47.098 INF request completed user.ip=127.0.0.1 request.method=GET request.url=/ request.proto=HTTP/1.1 response.status=200 response.size=697

# JSON
{"time":"2026-05-10T21:52:57.32380936+02:00","level":"INFO","msg":"request completed","user":{"ip":"127.0.0.1"},"request":{"method":"GET","url":"/","proto":"HTTP/1.1"},"response":{"status":200,"size":697}}