Skip to content

Commit 2392c53

Browse files
committed
update new method for status filter in log middleware, add documentation
1 parent 8419ac1 commit 2392c53

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

actix-web/src/middleware/logger.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,17 @@ impl Logger {
128128
}
129129

130130
/// Set a range of status to include in the logging
131-
pub fn status_range<R: RangeBounds<StatusCode>>(mut self, status: R) -> Self {
131+
///
132+
/// # Examples
133+
/// ```
134+
/// use actix_web::{middleware::Logger, App, http::StatusCode};
135+
///
136+
/// // Log only the requests with status code higher or equal to BAD_REQUEST(400)
137+
/// let app = App::new()
138+
/// .wrap(Logger::default().statuses(StatusCode::BAD_REQUEST..));
139+
///
140+
/// ```
141+
pub fn statuses<R: RangeBounds<StatusCode>>(mut self, status: R) -> Self {
132142
let inner = Rc::get_mut(&mut self.0).unwrap();
133143
inner.status_range = (status.start_bound().cloned(), status.end_bound().cloned());
134144
self

0 commit comments

Comments
 (0)