Function rouille::log_custom[][src]

pub fn log_custom<L, E, F>(
    req: &Request,
    log_ok_f: L,
    log_err_f: E,
    handler: F
) -> Response where
    L: Fn(&Request, &Response, Duration),
    E: Fn(&Request, Duration),
    F: FnOnce() -> Response
Expand description

Calls custom logging functions after processing a request.

This is nearly identical to the rouille::log function except it takes two logging functions that will be called with access to the request/response structs and the total execution duration of the handler.

Example

#[macro_use] extern crate log;
extern crate chrono;
use rouille::{Request, Response};


fn handle(request: &Request) -> Response {
    let now = chrono::Utc::now().format("%Y-%m-%d %H:%M:%S%.6f");
    let log_ok = |req: &Request, resp: &Response, _elap: std::time::Duration| {
        info!("{} {} {}", now, req.method(), req.raw_url());
    };
    let log_err = |req: &Request, _elap: std::time::Duration| {
        error!("{} Handler panicked: {} {}", now, req.method(), req.raw_url());
    };
    rouille::log_custom(request, log_ok, log_err, || {
        Response::text("hello world")
    })
}