1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

Log error results in Logger middleware (closes #938) (#984)

* Log error results in Logger middleware (closes #938)

* Log internal server errors with an ERROR log level

* Logger middleware: don't log 500 internal server errors, as Actix now logs them always

* Changelog
This commit is contained in:
Rotem Yaari 2019-07-18 11:31:18 +03:00 committed by Nikolay Kim
parent b36fdc46db
commit d03296237e
3 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,16 @@
# Changes
## [1.0.5] - ?
### Added
* Actix now logs errors resulting in "internal server error" responses always, with the `error`
logging level
### Fixed
* Restored logging of errors through the `Logger` middleware
## [1.0.4] - 2019-07-17
### Added

View File

@ -52,6 +52,9 @@ impl Response<Body> {
#[inline]
pub fn from_error(error: Error) -> Response {
let mut resp = error.as_response_error().render_response();
if resp.head.status == StatusCode::INTERNAL_SERVER_ERROR {
error!("Internal Server Error: {:?}", error);
}
resp.error = Some(error);
resp
}

View File

@ -9,12 +9,13 @@ use actix_service::{Service, Transform};
use bytes::Bytes;
use futures::future::{ok, FutureResult};
use futures::{Async, Future, Poll};
use log::debug;
use regex::Regex;
use time;
use crate::dev::{BodySize, MessageBody, ResponseBody};
use crate::error::{Error, Result};
use crate::http::{HeaderName, HttpTryFrom};
use crate::http::{HeaderName, HttpTryFrom, StatusCode};
use crate::service::{ServiceRequest, ServiceResponse};
use crate::HttpResponse;
@ -202,6 +203,12 @@ where
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
let res = futures::try_ready!(self.fut.poll());
if let Some(error) = res.response().error() {
if res.response().head().status != StatusCode::INTERNAL_SERVER_ERROR {
debug!("Error in response: {:?}", error);
}
}
if let Some(ref mut format) = self.format {
for unit in &mut format.0 {
unit.render_response(res.response());