Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Support] : Provided Support to Log the Current Thread name attribute as mentioned in the documentations at https://actix.rs/docs/middleware/ #3330

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions actix-web/src/middleware/logger.rs
Expand Up @@ -7,9 +7,10 @@
fmt::{self, Display as _},
future::Future,
marker::PhantomData,
pin::Pin,

Check warning on line 10 in actix-web/src/middleware/logger.rs

View workflow job for this annotation

GitHub Actions / fmt

Diff in /home/runner/work/actix-web/actix-web/actix-web/src/middleware/logger.rs
rc::Rc,
task::{Context, Poll},
thread::current
};

use actix_service::{Service, Transform};
Expand Down Expand Up @@ -512,6 +513,7 @@
"U" => FormatText::UrlPath,
"T" => FormatText::Time,
"D" => FormatText::TimeMillis,
"P" => FormatText::ThreadName,
_ => FormatText::Str(m.as_str().to_owned()),
});
}
Expand All @@ -531,6 +533,7 @@
#[derive(Debug, Clone)]
enum FormatText {
Str(String),
ThreadName,
Percent,
RequestLine,
RequestTime,
Expand Down Expand Up @@ -590,9 +593,12 @@
entry_time: OffsetDateTime,
) -> Result<(), fmt::Error> {
match self {
FormatText::Str(ref string) => fmt.write_str(string),

Check warning on line 596 in actix-web/src/middleware/logger.rs

View workflow job for this annotation

GitHub Actions / fmt

Diff in /home/runner/work/actix-web/actix-web/actix-web/src/middleware/logger.rs
FormatText::Percent => "%".fmt(fmt),
FormatText::ResponseSize => size.fmt(fmt),
FormatText::ThreadName => {
fmt.write_fmt(format_args!("{}", current().name().unwrap()))
}
FormatText::Time => {
let rt = OffsetDateTime::now_utc() - entry_time;
let rt = rt.as_seconds_f64();
Expand Down