python / python/cpython

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

Aperta
#145,238 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dagli attributi logging LogRecord di Python e dal comportamento di Formatter.format, quindi esamina la PR collegata gh-145655 e il punto di ingresso threading.get_native_id. Il lavoro è completato quando l’ID nativo del thread è disponibile come attributo selezionabile del log record senza interrompere le stringhe di formato che lo omettono.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
observability
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.