Request Logs
The request logging middleware allows you to define customized log statements to occur before and/or after each request is processed.
You can provide a log level and format string to be written before and after each request.
Itsi.rb
log_requests \
before: {
level: "INFO",
format: "[{request_id}] {method} {path_and_query} - {addr} "
},
after: {
level: "INFO",
format: "[{request_id}] └─ {status} in {response_time}"
}
The log statement can populated with several different placeholders, using String Rewrite functionality. Available values are:
before
Format String
request_id
- (A short, unique hexadecimal request identifier)request_id_full
- (A full 128-bit unique request identifier)method
- The HTTP methodpath
- The HTTP Pathaddr
- The client’s IP addresshost
- The request hostpath_and_query
- The path and query combinedquery
- The request query stringport
- The bound portstart_time
- The request start time<Header-Name>
: Any existing request header. For example{Accept}
or{Cookie}
will be replaced with its current value.
after
Format String
request_id
- (A short, unique hexadecimal request identifier)request_id_full
- (A full 128-bit unique request identifier)status
- The HTTP status codeaddr
- The client’s IP addressresponse_time
- The response time in milliseconds<Header-Name>
: Any existing response header. For example{Content-Type}
or{Set-Cookie}
will be replaced with its current value.
See String Rewrite for more advanced string manipulation options.
Path Attributes
In addition to this, any capture groups referenced by container location blocks are also made available, to be interpolated into the log statement. E.g.:
Itsi.rb
location "/users/:user_id" do # 1. If we capture user_id here.
log_requests before: {
level: "INFO",
format: "[{request_id}] User: {user_id}" # 2. Then we can log the user_id here.
}
end