Skip to content

Commit

Permalink
[Support] : Provided Support to Log the Current Thread name attribute…
Browse files Browse the repository at this point in the history
… as mentioned in the documentations at https://actix.rs/docs/middleware/
  • Loading branch information
Atri10 committed Apr 11, 2024
1 parent 5a5486b commit b075618
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions actix-web/src/middleware/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
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 @@ impl Format {
"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 @@ impl Format {
#[derive(Debug, Clone)]
enum FormatText {
Str(String),
ThreadName,
Percent,
RequestLine,
RequestTime,
Expand Down Expand Up @@ -593,6 +596,9 @@ impl FormatText {
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

0 comments on commit b075618

Please sign in to comment.