Skip to content

Commit

Permalink
CXXCBC-270 Rename logging macros (#323)
Browse files Browse the repository at this point in the history
* CXXCBC-270 Rename logging macros

Prevents clashing with client code.

* add missing changes
  • Loading branch information
davidkelly authored Nov 29, 2022
1 parent 7170d09 commit 65e328a
Show file tree
Hide file tree
Showing 37 changed files with 473 additions and 460 deletions.
4 changes: 2 additions & 2 deletions core/agent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class agent_impl
, collections_{ io_, { bucket_name_, config_.shim }, { config_.key_value.max_queue_size, config_.default_retry_strategy } }
, crud_{ io_, collections_, config_.default_retry_strategy }
{
LOG_DEBUG("SDK version: {}", meta::sdk_id());
LOG_DEBUG("creating new agent: {}", config_.to_string());
CB_LOG_DEBUG("SDK version: {}", meta::sdk_id());
CB_LOG_DEBUG("creating new agent: {}", config_.to_string());
}

[[nodiscard]] auto bucket_name() const -> const std::string&
Expand Down
4 changes: 2 additions & 2 deletions core/agent_group.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class agent_group_impl
config_.key_value,
})
{
LOG_DEBUG("SDK version: {}", meta::sdk_id());
LOG_DEBUG("creating new agent group: {}", config_.to_string());
CB_LOG_DEBUG("SDK version: {}", meta::sdk_id());
CB_LOG_DEBUG("creating new agent group: {}", config_.to_string());
}

auto open_bucket(const std::string& bucket_name) -> std::error_code
Expand Down
92 changes: 47 additions & 45 deletions core/bucket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ class bucket_impl
auto handle_error = [is_retry, req](std::error_code ec) {
// We only want to log an error on retries if the error isn't cancelled.
if (!is_retry || (is_retry && ec != errc::common::request_canceled)) {
LOG_ERROR("reschedule failed, failing request ({})", ec.message());
CB_LOG_ERROR("reschedule failed, failing request ({})", ec.message());
}

req->try_callback({}, ec);
};

LOG_DEBUG("request being re-queued. opaque={}, opcode={}", req->opaque_, req->command_);
CB_LOG_DEBUG("request being re-queued. opaque={}, opcode={}", req->opaque_, req->command_);

auto session = route_request(req);
if (session.empty() || !session.has_config()) {
Expand All @@ -227,7 +227,7 @@ class bucket_impl
}
auto data = codec_.encode_packet(*req);
if (!data) {
LOG_DEBUG("unable to encode packet. ec={}", data.error().message());
CB_LOG_DEBUG("unable to encode packet. ec={}", data.error().message());
handle_error(data.error());
return data.error();
}
Expand Down Expand Up @@ -302,17 +302,17 @@ class bucket_impl
void restart_node(std::size_t index, const std::string& hostname, const std::string& port)
{
if (closed_) {
LOG_DEBUG(R"({} requested to restart session, but the bucket has been closed already. idx={}, address="{}:{}")",
log_prefix_,
index,
hostname,
port);
CB_LOG_DEBUG(R"({} requested to restart session, but the bucket has been closed already. idx={}, address="{}:{}")",
log_prefix_,
index,
hostname,
port);
return;
}
{
std::scoped_lock lock(config_mutex_);
if (!config_->has_node_with_hostname(hostname)) {
LOG_TRACE(
CB_LOG_TRACE(
R"({} requested to restart session, but the node has been ejected from current configuration already. idx={}, address="{}:{}")",
log_prefix_,
index,
Expand All @@ -332,24 +332,24 @@ class bucket_impl

std::scoped_lock lock(sessions_mutex_);
if (auto ptr = sessions_.find(index); ptr == sessions_.end() || ptr->second.empty()) {
LOG_DEBUG(R"({} requested to restart session idx={}, which does not exist yet, initiate new one id="{}", address="{}:{}")",
log_prefix_,
index,
session.id(),
hostname,
port);
CB_LOG_DEBUG(R"({} requested to restart session idx={}, which does not exist yet, initiate new one id="{}", address="{}:{}")",
log_prefix_,
index,
session.id(),
hostname,
port);
} else {
const auto& old_session = ptr->second;
auto old_id = old_session.id();
sessions_.erase(ptr);
Expects(sessions_[index].empty());
LOG_DEBUG(R"({} restarting session idx={}, id=("{}" -> "{}"), address="{}:{}")",
log_prefix_,
index,
old_id,
session.id(),
hostname,
port);
CB_LOG_DEBUG(R"({} restarting session idx={}, id=("{}" -> "{}"), address="{}:{}")",
log_prefix_,
index,
old_id,
session.id(),
hostname,
port);
}

session.bootstrap(
Expand All @@ -361,7 +361,7 @@ class bucket_impl
return;
}
if (ec) {
LOG_WARNING(R"({} failed to restart session idx={}, ec={})", session.log_prefix(), this_index, ec.message());
CB_LOG_WARNING(R"({} failed to restart session idx={}, ec={})", session.log_prefix(), this_index, ec.message());
self->restart_node(this_index, hostname, port);
return;
}
Expand Down Expand Up @@ -393,7 +393,8 @@ class bucket_impl
new_session.bootstrap(
[self = shared_from_this(), new_session, h = std::move(handler)](std::error_code ec, const topology::configuration& cfg) mutable {
if (ec) {
LOG_WARNING(R"({} failed to bootstrap session ec={}, bucket="{}")", new_session.log_prefix(), ec.message(), self->name_);
CB_LOG_WARNING(
R"({} failed to bootstrap session ec={}, bucket="{}")", new_session.log_prefix(), ec.message(), self->name_);
} else {
size_t this_index = new_session.index();
new_session.on_configuration_update(self);
Expand Down Expand Up @@ -487,7 +488,7 @@ class bucket_impl
}
for (auto& [index, session] : old_sessions) {
if (session) {
LOG_DEBUG(R"({} shutdown session session="{}", idx={})", log_prefix_, session.id(), index);
CB_LOG_DEBUG(R"({} shutdown session session="{}", idx={})", log_prefix_, session.id(), index);
session.stop(retry_reason::do_not_retry);
}
}
Expand All @@ -501,18 +502,18 @@ class bucket_impl
{
std::scoped_lock lock(config_mutex_);
if (!config_) {
LOG_DEBUG("{} initialize configuration rev={}", log_prefix_, config.rev_str());
CB_LOG_DEBUG("{} initialize configuration rev={}", log_prefix_, config.rev_str());
} else if (config.force) {
LOG_DEBUG("{} forced to accept configuration rev={}", log_prefix_, config.rev_str());
CB_LOG_DEBUG("{} forced to accept configuration rev={}", log_prefix_, config.rev_str());
forced_config = true;
} else if (!config.vbmap) {
LOG_DEBUG("{} will not update the configuration old={} -> new={}, because new config does not have partition map",
log_prefix_,
config_->rev_str(),
config.rev_str());
CB_LOG_DEBUG("{} will not update the configuration old={} -> new={}, because new config does not have partition map",
log_prefix_,
config_->rev_str(),
config.rev_str());
return;
} else if (config_ < config) {
LOG_DEBUG("{} will update the configuration old={} -> new={}", log_prefix_, config_->rev_str(), config.rev_str());
CB_LOG_DEBUG("{} will update the configuration old={} -> new={}", log_prefix_, config_->rev_str(), config.rev_str());
} else {
return;
}
Expand Down Expand Up @@ -549,20 +550,20 @@ class bucket_impl
}
}
if (new_index < config.nodes.size()) {
LOG_DEBUG(R"({} rev={}, preserve session="{}", address="{}:{}")",
log_prefix_,
config.rev_str(),
session.id(),
session.bootstrap_hostname(),
session.bootstrap_port());
CB_LOG_DEBUG(R"({} rev={}, preserve session="{}", address="{}:{}")",
log_prefix_,
config.rev_str(),
session.id(),
session.bootstrap_hostname(),
session.bootstrap_port());
new_sessions[new_index] = std::move(session);
} else {
LOG_DEBUG(R"({} rev={}, drop session="{}", address="{}:{}")",
log_prefix_,
config.rev_str(),
session.id(),
session.bootstrap_hostname(),
session.bootstrap_port());
CB_LOG_DEBUG(R"({} rev={}, drop session="{}", address="{}:{}")",
log_prefix_,
config.rev_str(),
session.id(),
session.bootstrap_hostname(),
session.bootstrap_port());
asio::post(asio::bind_executor(
ctx_, [session = std::move(session)]() mutable { return session.stop(retry_reason::do_not_retry); }));
}
Expand All @@ -585,7 +586,8 @@ class bucket_impl
} else {
session = io::mcbp_session(client_id_, ctx_, origin, state_listener_, name_, known_features_);
}
LOG_DEBUG(R"({} rev={}, add session="{}", address="{}:{}")", log_prefix_, config.rev_str(), session.id(), hostname, port);
CB_LOG_DEBUG(
R"({} rev={}, add session="{}", address="{}:{}")", log_prefix_, config.rev_str(), session.id(), hostname, port);
session.bootstrap(
[self = shared_from_this(), session, forced_config, idx = node.index](std::error_code err,
topology::configuration cfg) mutable {
Expand Down
48 changes: 24 additions & 24 deletions core/cluster.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class cluster : public std::enable_shared_from_this<cluster>
}
if (!nodes.empty()) {
self->origin_.set_nodes(std::move(nodes));
LOG_INFO("replace list of bootstrap nodes with addresses from DNS SRV of \"{}\": [{}]",
hostname,
utils::join_strings(self->origin_.get_nodes(), ", "));
CB_LOG_INFO("replace list of bootstrap nodes with addresses from DNS SRV of \"{}\": [{}]",
hostname,
utils::join_strings(self->origin_.get_nodes(), ", "));
}
return self->do_open(std::forward<Handler>(handler));
});
Expand Down Expand Up @@ -343,18 +343,18 @@ class cluster : public std::enable_shared_from_this<cluster>
}

if (has_capella_host && !origin_.options().enable_tls) {
LOG_WARNING("[{}]: TLS is required when connecting to Couchbase Capella. Please enable TLS by prefixing "
"the connection string with \"couchbases://\" (note the final 's').",
id_);
CB_LOG_WARNING("[{}]: TLS is required when connecting to Couchbase Capella. Please enable TLS by prefixing "
"the connection string with \"couchbases://\" (note the final 's').",
id_);
}

if (origin_.options().enable_tls /* TLS is enabled */
&& origin_.options().trust_certificate.empty() /* No CA certificate (or other SDK-specific trust source) is specified */
&& origin_.options().tls_verify != tls_verify_mode::none /* The user did not disable all TLS verification */
&& has_non_capella_host /* The connection string has a hostname that does NOT end in ".cloud.couchbase.com" */) {
LOG_WARNING("[{}] When TLS is enabled, the cluster options must specify certificate(s) to trust or ensure that they are "
"available in system CA store. (Unless connecting to cloud.couchbase.com.)",
id_);
CB_LOG_WARNING("[{}] When TLS is enabled, the cluster options must specify certificate(s) to trust or ensure that they are "
"available in system CA store. (Unless connecting to cloud.couchbase.com.)",
id_);
}
}

Expand All @@ -370,30 +370,30 @@ class cluster : public std::enable_shared_from_this<cluster>
break;
}
if (origin_.options().trust_certificate.empty()) { // trust certificate is not explicitly specified
LOG_DEBUG(R"([{}]: use default CA for TLS verify)", id_);
CB_LOG_DEBUG(R"([{}]: use default CA for TLS verify)", id_);
std::error_code ec{};

// load system certificates
tls_.set_default_verify_paths(ec);
if (ec) {
LOG_WARNING(R"([{}]: failed to load system CAs: {})", id_, ec.message());
CB_LOG_WARNING(R"([{}]: failed to load system CAs: {})", id_, ec.message());
}

// add the Capella Root CA in addition to system CAs
tls_.add_certificate_authority(
asio::const_buffer(couchbase::core::default_ca::capellaCaCert, strlen(couchbase::core::default_ca::capellaCaCert)), ec);
if (ec) {
LOG_WARNING("[{}]: unable to load default CAs: {}", id_, ec.message());
CB_LOG_WARNING("[{}]: unable to load default CAs: {}", id_, ec.message());
// we don't consider this fatal and try to continue without it
}
} else { // trust certificate is explicitly specified
std::error_code ec{};
// load only the explicit certificate
// system and default capella certificates are not loaded
LOG_DEBUG(R"([{}]: use TLS verify file: "{}")", id_, origin_.options().trust_certificate);
CB_LOG_DEBUG(R"([{}]: use TLS verify file: "{}")", id_, origin_.options().trust_certificate);
tls_.load_verify_file(origin_.options().trust_certificate, ec);
if (ec) {
LOG_ERROR("[{}]: unable to load verify file \"{}\": {}", id_, origin_.options().trust_certificate, ec.message());
CB_LOG_ERROR("[{}]: unable to load verify file \"{}\": {}", id_, origin_.options().trust_certificate, ec.message());
return handler(ec);
}
}
Expand All @@ -402,23 +402,23 @@ class cluster : public std::enable_shared_from_this<cluster>
std::ofstream keylog(COUCHBASE_CXX_CLIENT_TLS_KEY_LOG_FILE, std::ios::out | std::ios::app | std::ios::binary);
keylog << std::string_view(line) << std::endl;
});
LOG_CRITICAL(
CB_LOG_CRITICAL(
"COUCHBASE_CXX_CLIENT_TLS_KEY_LOG_FILE was set to \"{}\" during build, all TLS keys will be logged for network analysis "
"(https://wiki.wireshark.org/TLS). DO NOT USE THIS BUILD IN PRODUCTION",
COUCHBASE_CXX_CLIENT_TLS_KEY_LOG_FILE);
#endif
if (origin_.credentials().uses_certificate()) {
std::error_code ec{};
LOG_DEBUG(R"([{}]: use TLS certificate chain: "{}")", id_, origin_.certificate_path());
CB_LOG_DEBUG(R"([{}]: use TLS certificate chain: "{}")", id_, origin_.certificate_path());
tls_.use_certificate_chain_file(origin_.certificate_path(), ec);
if (ec) {
LOG_ERROR("[{}]: unable to load certificate chain \"{}\": {}", id_, origin_.certificate_path(), ec.message());
CB_LOG_ERROR("[{}]: unable to load certificate chain \"{}\": {}", id_, origin_.certificate_path(), ec.message());
return handler(ec);
}
LOG_DEBUG(R"([{}]: use TLS private key: "{}")", id_, origin_.key_path());
CB_LOG_DEBUG(R"([{}]: use TLS private key: "{}")", id_, origin_.key_path());
tls_.use_private_key_file(origin_.key_path(), asio::ssl::context::file_format::pem, ec);
if (ec) {
LOG_ERROR("[{}]: unable to load private key \"{}\": {}", id_, origin_.key_path(), ec.message());
CB_LOG_ERROR("[{}]: unable to load private key \"{}\": {}", id_, origin_.key_path(), ec.message());
return handler(ec);
}
}
Expand All @@ -432,9 +432,9 @@ class cluster : public std::enable_shared_from_this<cluster>
if (self->origin_.options().network == "auto") {
self->origin_.options().network = config.select_network(self->session_.bootstrap_hostname());
if (self->origin_.options().network == "default") {
LOG_DEBUG(R"({} detected network is "{}")", self->session_.log_prefix(), self->origin_.options().network);
CB_LOG_DEBUG(R"({} detected network is "{}")", self->session_.log_prefix(), self->origin_.options().network);
} else {
LOG_INFO(R"({} detected network is "{}")", self->session_.log_prefix(), self->origin_.options().network);
CB_LOG_INFO(R"({} detected network is "{}")", self->session_.log_prefix(), self->origin_.options().network);
}
}
if (self->origin_.options().network != "default") {
Expand All @@ -452,9 +452,9 @@ class cluster : public std::enable_shared_from_this<cluster>
nodes.emplace_back(node);
}
self->origin_.set_nodes(nodes);
LOG_INFO("replace list of bootstrap nodes with addresses of alternative network \"{}\": [{}]",
self->origin_.options().network,
utils::join_strings(self->origin_.get_nodes(), ","));
CB_LOG_INFO("replace list of bootstrap nodes with addresses of alternative network \"{}\": [{}]",
self->origin_.options().network,
utils::join_strings(self->origin_.get_nodes(), ","));
}
self->session_manager_->set_configuration(config, self->origin_.options());
self->session_.on_configuration_update(self->session_manager_);
Expand Down
Loading

0 comments on commit 65e328a

Please sign in to comment.