Repository: apache/arrow
File: cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc (C++)

Code before:
  return std::make_shared<FlightSqlConnection>(odbc_version, version_);
}

odbcabstraction::Diagnostics& FlightSqlDriver::GetDiagnostics() { return diagnostics_; }

void FlightSqlDriver::SetVersion(std::string version) { version_ = std::move(version); }

void FlightSqlDriver::RegisterLog() {
  odbcabstraction::PropertyMap propertyMap;
  driver::odbcabstraction::ReadConfigFile(propertyMap, CONFIG_FILE_NAME);

  auto log_enable_iterator = propertyMap.find(SPDLogger::LOG_ENABLED);
  auto log_enabled = log_enable_iterator != propertyMap.end()
                         ? odbcabstraction::AsBool(log_enable_iterator->second)
                         : false;
  if (!log_enabled) {
    return;
  }

  auto log_path_iterator = propertyMap.find(SPDLogger::LOG_PATH);
  auto log_path = log_path_iterator != propertyMap.end() ? log_path_iterator->second : "";
  if (log_path.empty()) {
    return;
  }

  auto log_level_iterator = propertyMap.find(SPDLogger::LOG_LEVEL);
  auto log_level = ToLogLevel(log_level_iterator != propertyMap.end()
                                  ? std::stoi(log_level_iterator->second)
                                  : 1);
  if (log_level == odbcabstraction::LogLevel_OFF) {
    return;
  }

  auto maximum_file_size_iterator = propertyMap.find(SPDLogger::MAXIMUM_FILE_SIZE);
  auto maximum_file_size = maximum_file_size_iterator != propertyMap.end()
                               ? std::stoi(maximum_file_size_iterator->second)
                               : DEFAULT_MAXIMUM_FILE_SIZE;

  auto maximum_file_quantity_iterator = propertyMap.find(SPDLogger::FILE_QUANTITY);
  auto maximum_file_quantity = maximum_file_quantity_iterator != propertyMap.end()
                                   ? std::stoi(maximum_file_quantity_iterator->second)
                                   : 1;

  std::unique_ptr<odbcabstraction::SPDLogger> logger(new odbcabstraction::SPDLogger());

  logger->init(maximum_file_quantity, maximum_file_size, log_path, log_level);
  odbcabstraction::Logger::SetInstance(std::move(logger));
}

}  // namespace flight_sql
}  // namespace driver

Review comment (suggestion):
We don't want to enable logging only on INFO log level, right?
I think removing this condition (why do we need to disable?) or using `log_level <= ArrowLogLevel::ARROW_INFO` (disable all not important logs) is better. But we can revisit this later if it's needed.

Code after:
                                  .Map(arrow::internal::TrimString)
                                  .ValueOr("");
  if (log_level_str.empty()) {
    return;
  }

  auto log_level = ArrowLogLevel::ARROW_DEBUG;

  if (log_level_str == "fatal") {
    log_level = ArrowLogLevel::ARROW_FATAL;
  } else if (log_level_str == "error") {
    log_level = ArrowLogLevel::ARROW_ERROR;
  } else if (log_level_str == "warning") {
    log_level = ArrowLogLevel::ARROW_WARNING;
  } else if (log_level_str == "info") {
    log_level = ArrowLogLevel::ARROW_INFO;
  } else if (log_level_str == "debug") {
    log_level = ArrowLogLevel::ARROW_DEBUG;
  } else if (log_level_str == "trace") {
    log_level = ArrowLogLevel::ARROW_TRACE;
  }

  // Enable driver logging. Log files are not supported on Windows yet, since GLOG is not
  // tested fully on Windows.
  // Info log level is enabled by default.
  if (log_level != ArrowLogLevel::ARROW_INFO) {
    arrow::util::ArrowLog::StartArrowLog("arrow-flight-sql-odbc", log_level);
  }
}

}  // namespace flight_sql
}  // namespace driver