Skip to content

Commit

Permalink
grpc branch version < 1.66
Browse files Browse the repository at this point in the history
  • Loading branch information
meztez committed Nov 4, 2024
1 parent 5595fc1 commit c3c7d07
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/bqs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
#include <string>
#include <vector>
#include <grpc/grpc.h>

#if __has_include(<grpcpp/version_info.h>)
#include <grpcpp/version_info.h>
#if GRPC_CPP_VERSION_MAJOR >= 1 & GRPC_CPP_VERSION_MINOR >= 67
#define ABSL_LOGGING 1
#endif
#endif

#if GRPC_CPP_VERSION_MAJOR == 1 & GRPC_CPP_VERSION_MINOR <= 66
#ifndef ABSL_LOGGING
#include <grpc/support/log.h>
#endif

#if GRPC_CPP_VERSION_MAJOR >= 1 & GRPC_CPP_VERSION_MINOR >= 67
#ifdef ABSL_LOGGING
#include <absl/base/no_destructor.h>
#include <absl/base/log_severity.h>
#include <absl/log/globals.h>
Expand All @@ -30,13 +36,13 @@ using google::cloud::bigquery::storage::v1::BigQueryRead;

// -- Utilities and logging ----------------------------------------------------
// Define a default logger for gRPC
#if GRPC_CPP_VERSION_MAJOR == 1 & GRPC_CPP_VERSION_MINOR <= 66
#ifndef ABSL_LOGGING
void bqs_default_log(gpr_log_func_args* args) {
Rcpp::Rcerr << args->message << std::endl;
}
#endif

#if GRPC_CPP_VERSION_MAJOR >= 1 & GRPC_CPP_VERSION_MINOR >= 67
#ifdef ABSL_LOGGING
class RLogSink : public absl::LogSink {
public:
void Send(const absl::LogEntry& entry) override {
Expand All @@ -49,7 +55,7 @@ class RLogSink : public absl::LogSink {
// [[Rcpp::export(rng=false)]]
void bqs_set_log_verbosity(int severity) {

#if GRPC_CPP_VERSION_MAJOR == 1 & GRPC_CPP_VERSION_MINOR <= 66
#ifndef ABSL_LOGGING
//-1 UNSET
// 0 DEBUG
// 1 INFO
Expand All @@ -58,7 +64,7 @@ void bqs_set_log_verbosity(int severity) {
gpr_set_log_verbosity(static_cast<gpr_log_severity>(severity));
#endif

#if GRPC_CPP_VERSION_MAJOR >= 1 & GRPC_CPP_VERSION_MINOR >= 67
#ifdef ABSL_LOGGING
// -1 UNSET
// 0 INFO
// 1 WARNING
Expand All @@ -72,15 +78,17 @@ void bqs_set_log_verbosity(int severity) {
// Set gRPC default logger
// [[Rcpp::export(rng=false)]]
void bqs_init_logger() {
#if GRPC_CPP_VERSION_MAJOR == 1 & GRPC_CPP_VERSION_MINOR <= 66

#ifndef ABSL_LOGGING
gpr_set_log_function(bqs_default_log);
#endif
#if GRPC_CPP_VERSION_MAJOR >= 1 & GRPC_CPP_VERSION_MINOR >= 67

#ifdef ABSL_LOGGING
InitializeLog();
static absl::NoDestructor<RLogSink> r_log_sink;
AddLogSink(r_log_sink.get());

#endif

bqs_set_log_verbosity(2);
}

Expand Down

0 comments on commit c3c7d07

Please sign in to comment.