python / python/cpython

Add threading.get_native_id as an available log record attribute to choose from.

Đang mở
#145,238 7 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Feature or enhancement

Proposal:

It would be nice to have the native thread ID be one of the options for the log record attributes for python logging if at all possible.
https://docs.python.org/3/library/logging.html#logrecord-attributes

I came across this just now while forming a custom formatter class class SpecialLogFormatter(logging.Formatter): and passing into its constructor a flag to expose multiprocess details or to skip those using an unevaluated format string kept as member data. When I call the method def format(self, record: logging.LogRecord) -> str: I had to still conditionally check the process detail logging state because I need to pass in a separate variable to pass the threading.get_native_id information. Because the format string in the False case for the flag does not have that field in the format string to be rendered I'd get a key error in that case so I have to conditionally add it to the kwargs for the str.format invocation. I could avoid this per format invocation if the record object itself had the native thread ID present.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-145655

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với các thuộc tính logging LogRecord của Python và hành vi của Formatter.format, sau đó xem xét PR gh-145655 được liên kết và entry point threading.get_native_id. Công việc được hoàn thành khi ID thread gốc khả dụng dưới dạng một thuộc tính log record có thể chọn mà không làm hỏng các chuỗi định dạng không chứa nó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
observability
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.