Skip to content

fix: correct logger type from logging.Handler to logging.Logger#2209

Open
Turan Almammadov (turanalmammadov) wants to merge 1 commit intoconfluentinc:masterfrom
turanalmammadov:fix/logger-arg-docs-type
Open

fix: correct logger type from logging.Handler to logging.Logger#2209
Turan Almammadov (turanalmammadov) wants to merge 1 commit intoconfluentinc:masterfrom
turanalmammadov:fix/logger-arg-docs-type

Conversation

@turanalmammadov

Problem

Closes #1668

The documentation in docs/index.rst (and the corresponding online Kafka Client Configuration reference) documents the logger keyword argument as accepting a logging.Handler instance:

logger=logging.Handler kwarg: forward logs from the Kafka client to the provided logging.Handler instance.

However, the C implementation in src/confluent_kafka/src/confluent_kafka.c calls:

PyObject_CallMethod(h->logger, "log", "issss", level_map[level], "%s [%s] %s", fac, rd_kafka_name(rk), buf);

This is calling .log(level, msg, *args), which is a method on logging.Loggernot logging.Handler. logging.Handler exposes .emit(record), not .log(...).

The existing example code in the docs already uses logging.getLogger() (which returns a Logger), confirming the docs description was wrong.

Changes

  • docs/index.rst: Changed logging.Handlerlogging.Logger in the logger kwarg description. Added a clarifying note about the internal .log(level, msg, *args) call pattern.
  • src/confluent_kafka/cimpl.pyi: Added import logging and explicitly typed the logger parameter as Optional[logging.Logger] in the Producer and Consumer constructor overloads. This makes IDEs and type checkers surface the correct type rather than accepting Any via **kwargs.

Testing

The fix is documentation/type-stub only — no behavioral change. The existing examples in the docs already demonstrate the correct usage.

Made with Cursor

The documentation incorrectly stated that the `logger` keyword argument
accepts a `logging.Handler` instance. The C implementation calls
`logger.log(level, msg, *args)`, which is a `logging.Logger` method,
not a method on `logging.Handler`.

- Update docs/index.rst to reference `logging.Logger` instead of
  `logging.Handler`, and add a note clarifying the internal call pattern.
- Add `import logging` to cimpl.pyi and explicitly type the `logger`
  parameter as `Optional[logging.Logger]` in the `Producer` and
  `Consumer` constructor overloads so IDEs and type-checkers can
  surface the correct type.

Fixes confluentinc#1668

Made-with: Cursor
@confluent-cla-assistant
Copy link

Please sign the Contributor License Agreement here before this PR can be approved.
❌ turanalmammadov
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix docs about logger argument of Consumer and Producer

1 participant