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

add replacement for current thread name in Logger #3330

Closed
wants to merge 1 commit into from

Conversation

Atri10
Copy link

@Atri10 Atri10 commented Apr 11, 2024

PR Type: [Supoort]

This PR provides support to log the name of current thread which is handling the request.

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

Current behaviour with default Format shown below

r#"%a "%r" %s %b "%{Referer}i" "%{User-Agent}i" %T"#

We get Log:

[2024-04-11T17:29:13.432712900Z INFO  actix_web::middleware::logger] 127.0.0.1 "GET /spells HTTP/1.1" 200 285229 "-" "PostmanRuntime/7.37.3" 0.020495

New Behaviour (With custom Format shown below)

wrap(Logger::new(r#"[%P] [%a] ["%r"] [Response = %s] [Size = %b] "%{Referer}i" "%{User-Agent}i" Processed in %Tms."#))

We get Log:

[2024-04-11T17:31:15.122169300Z INFO  actix_web::middleware::logger] [actix-rt|system:0|arbiter:0] [127.0.0.1] ["GET /spells HTTP/1.1"] [Response = 200] [Size = 285229] "-" "PostmanRuntime/7.37.3" Processed in 0.020377ms.

@robjtede robjtede added B-semver-minor A-web project: actix-web labels Jun 7, 2024
@robjtede
Copy link
Member

robjtede commented Jun 7, 2024

I don't think I want this to be a standard option, it shouldn't usually matter which thread is handling the requests.

The behavior you're after can be achieved easily with a custom request replacement:

Logger::new("%{thread}xi")
  .custom_request_replace("thread", |_| std::thread::current().name().unwrap().to_owned())

@robjtede robjtede closed this Jun 7, 2024
@robjtede robjtede changed the title [Support] : Provided Support to Log the Current Thread name attribute as mentioned in the documentations at https://actix.rs/docs/middleware/ support current thread name in Logger Jun 7, 2024
@robjtede robjtede changed the title support current thread name in Logger add replacement for current thread name in Logger Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web project: actix-web B-semver-minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants