From 3e0374f8af2e1e15cd91630928f637b8513deee3 Mon Sep 17 00:00:00 2001 From: Brian Szmyd Date: Mon, 4 Nov 2024 18:02:16 -0700 Subject: [PATCH] Improve logging to main process. (#105) --- conanfile.py | 2 +- src/lib/logger.hpp | 1 + src/lib/messaging.cpp | 20 +++++++++++++------- src/lib/service.cpp | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/conanfile.py b/conanfile.py index 738a9c4..fa545ef 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,7 +3,7 @@ class NuRaftGrpcConan(ConanFile): name = "nuraft_grpc" - version = "6.1.2" + version = "6.1.3" homepage = "https://github.com/eBay/nuraft_mesg" description = "A gRPC service for NuRAFT" topics = ("ebay", "nublox", "raft") diff --git a/src/lib/logger.hpp b/src/lib/logger.hpp index 56e05d7..3e3b6b1 100644 --- a/src/lib/logger.hpp +++ b/src/lib/logger.hpp @@ -42,6 +42,7 @@ class nuraft_mesg_logger : public ::nuraft::logger { [[fallthrough]]; case 2: { LOGERRORMOD_USING_LOGGER(nuraft, _custom_logger, "ERROR {}", mesg); + LOGERRORMOD(nuraft, "ERROR {}", mesg); } break; ; case 3: { diff --git a/src/lib/messaging.cpp b/src/lib/messaging.cpp index 923793d..1e76317 100644 --- a/src/lib/messaging.cpp +++ b/src/lib/messaging.cpp @@ -137,14 +137,14 @@ void service::register_mgr_type(std::string const& group_type, register_params& nuraft::cb_func::ReturnCode service::callback_handler(std::string const& group_id, nuraft::cb_func::Type type, nuraft::cb_func::Param* param) { + auto const my_id = param->myId; + auto const leader_id = param->leaderId; switch (type) { case nuraft::cb_func::RemovedFromCluster: { - LOGINFO("Removed from cluster {}", group_id); + LOGINFO("Removed from cluster {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); exit_group(group_id); } break; case nuraft::cb_func::JoinedCluster: { - auto const my_id = param->myId; - auto const leader_id = param->leaderId; LOGINFO("Joined cluster: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); { std::lock_guard< std::mutex > lg(_manager_lock); @@ -152,11 +152,11 @@ nuraft::cb_func::ReturnCode service::callback_handler(std::string const& group_i } } break; case nuraft::cb_func::NewConfig: { - LOGDEBUGMOD(nuraft_mesg, "Cluster change for: {}", group_id); + LOGDEBUGMOD(nuraft_mesg, "Cluster change for: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); _config_change.notify_all(); } break; case nuraft::cb_func::BecomeLeader: { - LOGDEBUGMOD(nuraft_mesg, "I'm the leader of: {}!", group_id); + LOGINFOMOD(nuraft_mesg, "Elected leader of: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); { std::lock_guard< std::mutex > lg(_manager_lock); _is_leader[group_id] = true; @@ -164,12 +164,18 @@ nuraft::cb_func::ReturnCode service::callback_handler(std::string const& group_i _config_change.notify_all(); } break; case nuraft::cb_func::BecomeFollower: { - LOGDEBUGMOD(nuraft_mesg, "I'm a follower of: {} with the leader {}!", group_id, param->leaderId); + LOGINFOMOD(nuraft_mesg, "Became a follower of: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); { std::lock_guard< std::mutex > lg(_manager_lock); _is_leader[group_id] = false; } - } + } break; + case nuraft::cb_func::SaveSnapshot: { + LOGINFOMOD(nuraft_mesg, "Received Snapshot to sync for: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); + } break; + case nuraft::cb_func::FollowerLost: { + LOGINFOMOD(nuraft_mesg, "Lost follower: {}, [leader_id:{}, my_id:{}]", param->peerId, group_id, leader_id, my_id); + } break; default: break; }; diff --git a/src/lib/service.cpp b/src/lib/service.cpp index 2d7e4a0..3d0fa58 100644 --- a/src/lib/service.cpp +++ b/src/lib/service.cpp @@ -205,7 +205,7 @@ bool msg_service::raftStep(const sisl::AsyncRpcDataPtr< Messaging, RaftGroupMsg, // Verify this is for the service it was intended for auto const& base = request.msg().base(); if (intended_addr != _service_address) { - LOGWARNMOD(nuraft_mesg, "Recieved mesg for {} intended for {}, we are {}", + LOGWARNMOD(nuraft_mesg, "Received mesg for [{}:{}] intended for {}, we are {}", group_name, nuraft::msg_type_to_string(nuraft::msg_type(base.type())), intended_addr, _service_address); rpc_data->set_status(::grpc::Status( ::grpc::INVALID_ARGUMENT,