Function warp::filters::log::log

source · []
pub fn log(name: &'static str) -> Log<impl Fn(Info<'_>) + Copy>
Expand description

Create a wrapping filter with the specified name as the target.

This uses the default access logging format, and log records produced will have their target set to name.

Example

use warp::Filter;

// If using something like `pretty_env_logger`,
// view logs by setting `RUST_LOG=example::api`.
let log = warp::log("example::api");
let route = warp::any()
    .map(warp::reply)
    .with(log);
Examples found in repository?
examples/todos.rs (line 28)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
async fn main() {
    if env::var_os("RUST_LOG").is_none() {
        // Set `RUST_LOG=todos=debug` to see debug logs,
        // this only shows access logs.
        env::set_var("RUST_LOG", "todos=info");
    }
    pretty_env_logger::init();

    let db = models::blank_db();

    let api = filters::todos(db);

    // View access logs by setting `RUST_LOG=todos`.
    let routes = api.with(warp::log("todos"));
    // Start up the server...
    warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}