From 8f33dec026377d8c276ede60cdc9be6c146d071a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 2 Dec 2017 00:24:26 -0800 Subject: [PATCH] add logging doc section --- guide/src/SUMMARY.md | 6 +++++ guide/src/qs_10.md | 1 + guide/src/qs_11.md | 59 ++++++++++++++++++++++++++++++++++++++++++++ guide/src/qs_12.md | 1 + guide/src/qs_7.md | 1 + guide/src/qs_8.md | 1 + guide/src/qs_9.md | 1 + 7 files changed, 70 insertions(+) create mode 100644 guide/src/qs_10.md create mode 100644 guide/src/qs_11.md create mode 100644 guide/src/qs_12.md create mode 100644 guide/src/qs_7.md create mode 100644 guide/src/qs_8.md create mode 100644 guide/src/qs_9.md diff --git a/guide/src/SUMMARY.md b/guide/src/SUMMARY.md index bfc06879..5c3b165b 100644 --- a/guide/src/SUMMARY.md +++ b/guide/src/SUMMARY.md @@ -6,3 +6,9 @@ - [Handler](./qs_4.md) - [Resources and Routes](./qs_5.md) - [Application state](./qs_6.md) +- [Request](./qs_7.md) +- [Response](./qs_8.md) +- [WebSockets](./qs_9.md) +- [User sessions](./qs_10.md) +- [Logging](./qs_11.md) +- [Static file handling](./qs_12.md) diff --git a/guide/src/qs_10.md b/guide/src/qs_10.md new file mode 100644 index 00000000..0c28628e --- /dev/null +++ b/guide/src/qs_10.md @@ -0,0 +1 @@ +# User sessions diff --git a/guide/src/qs_11.md b/guide/src/qs_11.md new file mode 100644 index 00000000..5aed847c --- /dev/null +++ b/guide/src/qs_11.md @@ -0,0 +1,59 @@ +# Logging + +Logging is implemented as middleware. Middlewares get executed in same order as registraton order. +It is common to register logging middleware as first middleware for application. +Logging middleware has to be registered for each application. + +## Usage + +Create `Logger` middlewares with the specified `format`. +Default `Logger` could be created with `default` method, it uses the default format: + +```ignore + %a %t "%r" %s %b "%{Referrer}i" "%{User-Agent}i" %T +``` +```rust +extern crate actix_web; +use actix_web::Application; +use actix_web::middlewares::Logger; + +fn main() { + Application::default("/") + .middleware(Logger::default()) + .middleware(Logger::new("%a %{User-Agent}i")) + .finish(); +} +``` + +Here is example of default logging format: + +``` +INFO:actix_web::middlewares::logger: 127.0.0.1:59934 [02/Dec/2017:00:21:43 -0800] "GET / HTTP/1.1" 302 0 "-" "curl/7.54.0" 0.000397 +INFO:actix_web::middlewares::logger: 127.0.0.1:59947 [02/Dec/2017:00:22:40 -0800] "GET /index.html HTTP/1.1" 200 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0" 0.000646 +``` + +## 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 + + `%P` The process ID of the child that serviced the request + + `%r` First line of request + + `%s` Response status code + + `%b` Size of response in bytes, including HTTP headers + + `%T` Time taken to serve the request, in seconds with floating fraction in .06f format + + `%D` Time taken to serve the request, in milliseconds + + `%{FOO}i` request.headers['FOO'] + + `%{FOO}o` response.headers['FOO'] + + `%{FOO}e` os.environ['FOO'] diff --git a/guide/src/qs_12.md b/guide/src/qs_12.md new file mode 100644 index 00000000..8220368d --- /dev/null +++ b/guide/src/qs_12.md @@ -0,0 +1 @@ +# Static file handling diff --git a/guide/src/qs_7.md b/guide/src/qs_7.md new file mode 100644 index 00000000..0d92e9fd --- /dev/null +++ b/guide/src/qs_7.md @@ -0,0 +1 @@ +# Request diff --git a/guide/src/qs_8.md b/guide/src/qs_8.md new file mode 100644 index 00000000..465fa362 --- /dev/null +++ b/guide/src/qs_8.md @@ -0,0 +1 @@ +# Response diff --git a/guide/src/qs_9.md b/guide/src/qs_9.md new file mode 100644 index 00000000..7627a157 --- /dev/null +++ b/guide/src/qs_9.md @@ -0,0 +1 @@ +# WebSockets