h2: use proper logging
This commit is contained in:
parent
b5834a604b
commit
539dff7c2a
|
@ -70,8 +70,8 @@ class Http2Connection(HttpConnection):
|
|||
super().__init__(context, conn)
|
||||
if self.debug:
|
||||
self.h2_conf.logger = H2ConnectionLogger(
|
||||
f"{human.format_address(self.context.client.peername)}: "
|
||||
f"{self.__class__.__name__}"
|
||||
self.context.client.peername,
|
||||
self.__class__.__name__
|
||||
)
|
||||
self.h2_conf.validate_inbound_headers = (
|
||||
self.context.options.validate_inbound_headers
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import collections
|
||||
import logging
|
||||
from typing import Dict, List, NamedTuple, Tuple
|
||||
|
||||
import h2.config
|
||||
|
@ -9,16 +10,29 @@ import h2.settings
|
|||
import h2.stream
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class H2ConnectionLogger(h2.config.DummyLogger):
|
||||
def __init__(self, name: str):
|
||||
def __init__(self, peername: tuple, conn_type: str):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.peername = peername
|
||||
self.conn_type = conn_type
|
||||
|
||||
def debug(self, fmtstr, *args):
|
||||
print(f"{self.name} h2 (debug): {fmtstr % args}")
|
||||
logger.debug(
|
||||
f"{self.conn_type} {fmtstr}",
|
||||
*args,
|
||||
extra={"client": self.peername}
|
||||
)
|
||||
|
||||
def trace(self, fmtstr, *args):
|
||||
print(f"{self.name} h2 (trace): {fmtstr % args}")
|
||||
logger.log(
|
||||
logging.DEBUG - 1,
|
||||
f"{self.conn_type} {fmtstr}",
|
||||
*args,
|
||||
extra={"client": self.peername}
|
||||
)
|
||||
|
||||
|
||||
class SendH2Data(NamedTuple):
|
||||
|
|
Loading…
Reference in New Issue