Skip to content

Commit 7bc4a41

Browse files
committed
more logging
1 parent a117a6d commit 7bc4a41

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/h2/config.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
Objects for controlling the configuration of the HTTP/2 stack.
77
"""
88

9+
import sys
10+
911

1012
class _BooleanConfigOption:
1113
"""
@@ -27,7 +29,7 @@ def __set__(self, instance, value):
2729

2830
class DummyLogger:
2931
"""
30-
An Logger object that does not actual logging, hence a DummyLogger.
32+
A Logger object that does not actual logging, hence a DummyLogger.
3133
3234
For the class the log operation is merely a no-op. The intent is to avoid
3335
conditionals being sprinkled throughout the h2 code for calls to
@@ -49,6 +51,29 @@ def trace(self, *vargs, **kwargs):
4951
pass
5052

5153

54+
class OutputLogger:
55+
"""
56+
A Logger object that prints to stderr or any other file-like object.
57+
58+
This class is provided for convinience and not part of the stable API.
59+
60+
:param file: A file-like object passed to the print function.
61+
Defaults to ``sys.stderr``.
62+
:param trace: Enables trace-level output. Defaults to ``False``.
63+
"""
64+
def __init__(self, file=sys.stderr, trace=False):
65+
super().__init__()
66+
self.file = file
67+
self.trace = trace
68+
69+
def debug(self, fmtstr, *args):
70+
print(f"h2 (debug): {fmtstr % args}", file=self.file)
71+
72+
def trace(self, fmtstr, *args):
73+
if self.trace:
74+
print(f"h2 (trace): {fmtstr % args}", file=self.file)
75+
76+
5277
class H2Configuration:
5378
"""
5479
An object that controls the way a single HTTP/2 connection behaves.

src/h2/connection.py

+1
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,7 @@ def _receive_frame(self, frame):
14811481
.. versionchanged:: 2.0.0
14821482
Removed from the public API.
14831483
"""
1484+
self.config.logger.trace("Received frame: %s", repr(frame))
14841485
try:
14851486
# I don't love using __class__ here, maybe reconsider it.
14861487
frames, events = self._frame_dispatch_table[frame.__class__](frame)

src/h2/utilities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def validate_headers(headers, hdr_validation_flags):
203203
# checking remains somewhat expensive, and attempts should be made wherever
204204
# possible to reduce the time spent doing them.
205205
#
206-
# For example, we avoid tuple upacking in loops because it represents a
206+
# For example, we avoid tuple unpacking in loops because it represents a
207207
# fixed cost that we don't want to spend, instead indexing into the header
208208
# tuples.
209209
headers = _reject_uppercase_header_fields(

0 commit comments

Comments
 (0)