There is an option to pass in a Logger when creating the pulsar client to log to. It seems this does not work when creating resources.
Reproduction:
First, run a pulsar standalone instance:
docker run -it -p 6650:6650 -p 8080:8080 --tmpfs /pulsar/data apachepulsar/pulsar:3.1.0 bin/pulsar standalone
And then run this code:
importloggingimportpulsarpulsar_logger=logging.getLogger("pulsarDummyLogger")
pulsar_logger.setLevel(logging.ERROR)
logging.basicConfig(level=logging.INFO, format="{message}", style="{")
logging.info("This should be logged")
pulsar_logger.info("This isn't logged (correctly)")
client=pulsar.Client("pulsar://localhost:6650", logger=pulsar_logger)
producer=client.create_producer("A")
producer.close()
client.close()It will write this to your terminal:
This should be logged
2024-01-15 14:12:08.947 DEBUG [140254733069184] ProducerImpl:128 | [persistent://public/default/A, standalone-0-4] ~ProducerImpl
2024-01-15 14:12:08.948 INFO [140254733069184] ProducerImpl:722 | Producer - [persistent://public/default/A, standalone-0-4] , [batching = off]
Potentially related to apache/pulsar#7713
I note that, if you set the log level to INFO for the pulsar logger, you do get more output:
This should be logged
This isn't logged (correctly)[<none> -> pulsar://localhost:6650] Create ClientConnection, timeout=10000Created connection for pulsar://localhost:6650[127.0.0.1:53354 -> 127.0.0.1:6650] Connected to broker[persistent://public/default/A, ] Getting connection from pool[persistent://public/default/A, ] Created producer on broker [127.0.0.1:53354 -> 127.0.0.1:6650] [persistent://public/default/A, standalone-0-6] Closing producer for topic 0x7f4478002510[persistent://public/default/A, standalone-0-6] Closed producer 0Closing Pulsar client with 0 producers and 0 consumers[127.0.0.1:53354 -> 127.0.0.1:6650] Connection disconnected[127.0.0.1:53354 -> 127.0.0.1:6650] Destroyed connection2024-01-15 14:13:51.273 DEBUG [139932214320000] ProducerImpl:128 | [persistent://public/default/A, standalone-0-6] ~ProducerImpl2024-01-15 14:13:51.273 INFO [139932214320000] ProducerImpl:722 | Producer - [persistent://public/default/A, standalone-0-6] , [batching = off]
But I would expect that the logger is still used when creating resources like producers, readers, and consumers.
Expected behaviour
We can control the formatting and level of the logs produced by the pulsar client. Hopefully this is an easy fix, and the custom logger in the parent client can simply be passed on, if set, to the producer/consumer/readers when they are created
There is an option to pass in a Logger when creating the pulsar client to log to. It seems this does not work when creating resources.
Reproduction:
First, run a pulsar standalone instance:
And then run this code:
It will write this to your terminal:
Potentially related to apache/pulsar#7713
I note that, if you set the log level to INFO for the pulsar logger, you do get more output:
But I would expect that the logger is still used when creating resources like producers, readers, and consumers.
Expected behaviour
We can control the formatting and level of the logs produced by the pulsar client. Hopefully this is an easy fix, and the custom logger in the parent client can simply be passed on, if set, to the producer/consumer/readers when they are created