pub struct Logger { /* private fields */ }Expand description
Middleware for logging request and response info to the terminal.
Logger middleware uses standard log crate to log information. You should
enable logger for ntex package to see access log.
(env_logger or similar)
§Usage
Create Logger middleware with the specified format.
Default Logger could be created with default method, it uses the
default format:
%a "%r" %s %b "%{Referer}i" "%{User-Agent}i" %Tuse ntex::web::App;
use ntex::web::middleware::Logger;
fn main() {
let app = App::default()
.middleware(Logger::default())
.middleware(Logger::new("%a %{User-Agent}i"));
}§Format
%% The percent sign
%a Remote IP-address (IP-address of proxy if using reverse proxy)
%t Time when the request was started to process (in HTTP-date format,
e.g. Thu, 04 Sep 2025 15:33:20 GMT)
%r First line of request
%s Response status code
%b Size of response in bytes, excluding HTTP headers
%T Time taken to serve the request, in seconds with six decimal places
%D Time taken to serve the request, in milliseconds with six decimal
places
%U Request URL path, without the query string
%{FOO}i request.headers["FOO"]
%{FOO}o response.headers["FOO"]
%{FOO}e os.environ["FOO"]