Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions actix-web/src/middleware/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use actix_service::{Service, Transform};
use actix_utils::future::{ready, Ready};
use bytes::Bytes;
use futures_core::ready;
use log::{debug, warn};
use log::{debug, warn, Level};
use pin_project_lite::pin_project;
use regex::{Regex, RegexSet};
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
Expand Down Expand Up @@ -363,6 +363,12 @@ where
debug!("Error in response: {:?}", error);
}

let level = match res.response().status().as_u16() {
300..=499 => Level::Warn,
500..=599 => Level::Error,
_ => Level::Info,
};

let res = if let Some(ref mut format) = this.format {
// to avoid polluting all the Logger types with the body parameter we swap the body
// out temporarily since it's not usable in custom response functions anyway
Expand Down Expand Up @@ -393,6 +399,7 @@ where
format,
size: 0,
log_target,
level,
})))
}
}
Expand All @@ -405,6 +412,7 @@ pin_project! {
size: usize,
time: OffsetDateTime,
log_target: Cow<'static, str>,
level: Level,
}

impl<B> PinnedDrop for StreamLog<B> {
Expand All @@ -417,8 +425,9 @@ pin_project! {
Ok(())
};

log::info!(
log::log!(
target: this.log_target.as_ref(),
this.level,
"{}", FormatDisplay(&render)
);
}
Expand Down