@@ -203,10 +203,6 @@ def __str__(self):
203
203
def copy_to (self , record ):
204
204
pass
205
205
206
- def copy_to_twisted_log_entry (self , record ):
207
- record ["request" ] = None
208
- record ["scope" ] = None
209
-
210
206
def start (self , rusage : "Optional[resource._RUsage]" ):
211
207
pass
212
208
@@ -372,13 +368,6 @@ def copy_to(self, record) -> None:
372
368
# we also track the current scope:
373
369
record .scope = self .scope
374
370
375
- def copy_to_twisted_log_entry (self , record ) -> None :
376
- """
377
- Copy logging fields from this context to a Twisted log record.
378
- """
379
- record ["request" ] = self .request
380
- record ["scope" ] = self .scope
381
-
382
371
def start (self , rusage : "Optional[resource._RUsage]" ) -> None :
383
372
"""
384
373
Record that this logcontext is currently running.
@@ -542,28 +531,25 @@ def record_event_fetch(self, event_count: int) -> None:
542
531
class LoggingContextFilter (logging .Filter ):
543
532
"""Logging filter that adds values from the current logging context to each
544
533
record.
545
- Args:
546
- **defaults: Default values to avoid formatters complaining about
547
- missing fields
548
534
"""
549
535
550
- def __init__ (self , ** defaults ) -> None :
551
- self .defaults = defaults
536
+ def __init__ (self , request : str = "" ) :
537
+ self ._default_request = request
552
538
553
539
def filter (self , record ) -> Literal [True ]:
554
540
"""Add each fields from the logging contexts to the record.
555
541
Returns:
556
542
True to include the record in the log output.
557
543
"""
558
544
context = current_context ()
559
- for key , value in self .defaults .items ():
560
- setattr (record , key , value )
545
+ record .request = self ._default_request
561
546
562
547
# context should never be None, but if it somehow ends up being, then
563
548
# we end up in a death spiral of infinite loops, so let's check, for
564
549
# robustness' sake.
565
550
if context is not None :
566
- context .copy_to (record )
551
+ # Logging is interested in the request.
552
+ record .request = context .request
567
553
568
554
return True
569
555
0 commit comments