mirror of https://github.com/fafhrd91/actix-web
[SUPPORT] Added Current Thread Name Support In Logging as Mentioned in Documentations at https://actix.rs/docs/middleware/
This commit is contained in:
parent
5a5486b484
commit
1d990a25d7
|
@ -10,6 +10,7 @@ use std::{
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
|
thread::current
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_service::{Service, Transform};
|
use actix_service::{Service, Transform};
|
||||||
|
@ -512,6 +513,7 @@ impl Format {
|
||||||
"U" => FormatText::UrlPath,
|
"U" => FormatText::UrlPath,
|
||||||
"T" => FormatText::Time,
|
"T" => FormatText::Time,
|
||||||
"D" => FormatText::TimeMillis,
|
"D" => FormatText::TimeMillis,
|
||||||
|
"P" => FormatText::ThreadName,
|
||||||
_ => FormatText::Str(m.as_str().to_owned()),
|
_ => FormatText::Str(m.as_str().to_owned()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -531,6 +533,7 @@ impl Format {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum FormatText {
|
enum FormatText {
|
||||||
Str(String),
|
Str(String),
|
||||||
|
ThreadName,
|
||||||
Percent,
|
Percent,
|
||||||
RequestLine,
|
RequestLine,
|
||||||
RequestTime,
|
RequestTime,
|
||||||
|
@ -610,6 +613,9 @@ impl FormatText {
|
||||||
"-".fmt(fmt)
|
"-".fmt(fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
FormatText::ThreadName() => {
|
||||||
|
fmt.write_fmt(format_args!("{}", current().name().unwrap()))
|
||||||
|
}
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue