Skip to content

Commit f9b2d16

Browse files
[docs] Add guide to avoid logs from the default logger (#195)
Fixes #194 ### Motivation When the Python logger is configured as the logger, during the exit process of a Python script, the default logger will be used for logging instead because the Python logger is unavailable after the interpreter is finalized. It might lead to some unexpected outputs to standard output.
1 parent 4b61547 commit f9b2d16

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pulsar/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,19 @@ def __init__(self, service_url,
532532
matches the common name on the TLS certificate presented by the endpoint.
533533
logger: optional
534534
Set a Python logger for this Pulsar client. Should be an instance of `logging.Logger`.
535+
It should be noted that if the Python logger is configured, during the termination of the Python
536+
interpreter, the Python logger will be unavailable and the default logger will be used for logging.
537+
To avoid strange behavior, you'd better delete all instances explicitly before exiting.
538+
539+
.. code-block:: python
540+
541+
import logging
542+
client = Client(service_url, logger=logging.getLogger('pulsar'))
543+
producer = client.create_producer(topic)
544+
# ...
545+
del producer
546+
del client
547+
535548
connection_timeout_ms: int, default=10000
536549
Set timeout in milliseconds on TCP connections.
537550
listener_name: str, optional

0 commit comments

Comments
 (0)