diff --git a/src/bqs.cpp b/src/bqs.cpp index 16dadff..9f6ad55 100644 --- a/src/bqs.cpp +++ b/src/bqs.cpp @@ -2,13 +2,19 @@ #include #include #include + +#if __has_include() #include +#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 #endif -#if GRPC_CPP_VERSION_MAJOR >= 1 & GRPC_CPP_VERSION_MINOR >= 67 +#ifdef ABSL_LOGGING #include #include #include @@ -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 { @@ -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 @@ -58,7 +64,7 @@ void bqs_set_log_verbosity(int severity) { gpr_set_log_verbosity(static_cast(severity)); #endif -#if GRPC_CPP_VERSION_MAJOR >= 1 & GRPC_CPP_VERSION_MINOR >= 67 +#ifdef ABSL_LOGGING // -1 UNSET // 0 INFO // 1 WARNING @@ -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 r_log_sink; AddLogSink(r_log_sink.get()); - #endif + bqs_set_log_verbosity(2); }