Skip to content

Commit

Permalink
fix: kafka logging to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
nepridumalnik committed Nov 27, 2024
1 parent 199115f commit 4f9bfce
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kafka/src/kafka/impl/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@
#include <userver/yaml_config/yaml_config.hpp>

#include <kafka/impl/error_buffer.hpp>
#include <kafka/impl/log_level.hpp>

USERVER_NAMESPACE_BEGIN

namespace kafka::impl {

namespace {

/// @brief Redirect `librdkafka` logs to `userver` logs.
///
/// @see
/// https://docs.confluent.io/platform/current/clients/librdkafka/html/rdkafka_8h.html#a06ade2ca41f32eb82c6f7e3d4acbe19f
void KafkaLogCallback([[maybe_unused]] const rd_kafka_t*, int level, const char* fac, const char* buf) noexcept {
LOG(userver::kafka::impl::convertRdKafkaLogLevelToLoggingLevel(level)) << fac << buf;
}

template <class SupportedList>
bool IsSupportedOption(const SupportedList& supported_options, const std::string& configured_option) {
return utils::ContainsIf(supported_options, [&configured_option](std::string_view supported_option) {
Expand Down Expand Up @@ -282,6 +291,8 @@ void Configuration::SetOption(const char* option, const char* value, T to_print)
#pragma GCC diagnostic pop
#endif
if (err == RD_KAFKA_CONF_OK) {
rd_kafka_conf_set_log_cb(conf_.GetHandle(), KafkaLogCallback);

LOG_INFO() << fmt::format("Kafka conf option: '{}' -> '{}'", option, to_print);
return;
}
Expand Down

0 comments on commit 4f9bfce

Please sign in to comment.