confluentinc / confluentinc/confluent-kafka-python

Fix docs about `logger` argument of Consumer and Producer

Open
#1,668 1 comment 1 reaction 0 assignees View on GitHub
enhancement priority:high status:waiting-for-interest
Dominant language
Python
Stars
509
Forks
964
Avg merge
2d 2h
Merged PRs (30d)
14

Description

Description
===========

Documentation of [Kafka Client Configuration](https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#kafka-client-configuration) mentions keyword-only argument `logger` in constructors of Consumer and Producer.

![image](https://github.com/confluentinc/confluent-kafka-python/assets/35541026/6eaf5e16-38fa-485f-8324-9e6ec5f760b1)

This argument is not listed in documentation of [Consumer](https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#consumer) and [Producer](https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#producer).

In addition, the paragraph on the screenshot contains incorrect type for `logger`. The documentation states type `logging.Handler`, but in the provided example instance of class `logging.Logger` is passed; `logging.Logger` is not a subclass of `logging.Handler`.

As per my tests, any object with method `log` is accepted; this method must accept level, msg and arbitrarily many arguments.

Test code below.
`confluent_kafka.version()` -- `('2.2.0', 33685504)`.
`confluent_kafka.libversion()` -- `('2.2.0', 33685759)`.

```python
import logging
import sys
from logging import LoggerAdapter, StreamHandler, getLogger
from time import sleep
from typing import Any

from confluent_kafka import Consumer

def _print(*args):
print(*args, file=sys.stderr, flush=True)

class L:
@staticmethod
def log(*args, **kwargs):
_print(args)
_print(kwargs)

class StrictL:
@staticmethod
def log(level: int, msg: str, /, *args: Any):
_print(f'{level}:\t{msg % args}')

def main():
config = {
'bootstrap.servers': 'localhost:9092',
'security.protocol': 'plaintext',
'sasl.mechanism': 'PLAIN',
'client.id': 'test',
'group.id': 'test',
}

_print('Test Logger')

c = Consumer(config, logger=getLogger())
c.poll(5)
c.close()

_print('\nTest LoggerAdapter')

c = Consumer(config, logger=LoggerAdapter(getLogger(), {'spider': None}))
c.poll(5)
c.close()

_print('\nTest logging')

c = Consumer(config, logger=logging)
c.poll(5)
c.close()

_print('\nTest L')

c = Consumer(config, logger=L)
c.poll(5)
c.close()

_print('\nTest StrictL')

c = Consumer(config, logger=StrictL)
c.poll(5)
c.close()

_print('\nTest StreamHandler')

try:
c = Consumer(config, logger=StreamHandler())
c.poll(5)
except AttributeError as e:
_print(e.__class__.__name__, e)
finally:
c.close()

if __name__ == '__main__':
main()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.