Skip to content

Commit

Permalink
Logging improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd committed Oct 4, 2023
1 parent 7ba33ac commit 74d9702
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/lib/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ class nuraft_mesg_logger : public ::nuraft::logger {
void put_details(int level, const char* source_file, const char* func_name, size_t line_number,
const std::string& log_line) override {
auto const mesg =
fmt::format("[vol={}] {}:{}#{} : {}", _group_id, file_name(source_file), func_name, line_number, log_line);
fmt::format("[group={}] {}:{}#{} : {}", _group_id, file_name(source_file), func_name, line_number, log_line);
switch (level) {
case 1:
[[fallthrough]];
case 2: {
LOGERRORMOD(nuraft, "{}", mesg);
LOGERRORMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg);
} break;
case 3: {
LOGWARNMOD(nuraft, "{}", mesg);
LOGWARNMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg);
} break;
case 4: {
LOGINFOMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg);
Expand Down
20 changes: 10 additions & 10 deletions src/lib/manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,32 @@ nuraft::cb_func::ReturnCode ManagerImpl::callback_handler(group_id_t const& grou
nuraft::cb_func::Param* param) {
switch (type) {
case nuraft::cb_func::RemovedFromCluster: {
LOGINFO("Removed from cluster {}", group_id);
LOGINFO("Removed from cluster [group={}]", group_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: {}, [l_id:{},my_id:{}]", group_id, leader_id, my_id);
LOGINFO("Joined cluster: [group={}], [l_id:{},my_id:{}]", group_id, leader_id, my_id);
{
std::lock_guard< std::mutex > lg(_manager_lock);
_is_leader[group_id] = (leader_id == my_id);
}
} break;
case nuraft::cb_func::NewConfig: {
LOGDEBUGMOD(nuraft_mesg, "Cluster change for: {}", group_id);
LOGDEBUGMOD(nuraft_mesg, "Cluster change for: [group={}]", group_id);
_config_change.notify_all();
} break;
case nuraft::cb_func::BecomeLeader: {
LOGDEBUGMOD(nuraft_mesg, "I'm the leader of: {}!", group_id);
LOGDEBUGMOD(nuraft_mesg, "I'm the leader of: [group={}]!", group_id);
{
std::lock_guard< std::mutex > lg(_manager_lock);
_is_leader[group_id] = true;
}
_config_change.notify_all();
} break;
case nuraft::cb_func::BecomeFollower: {
LOGDEBUGMOD(nuraft_mesg, "I'm a follower of: {}!", group_id);
LOGINFOMOD(nuraft_mesg, "I'm a follower of: [group={}]!", group_id);
{
std::lock_guard< std::mutex > lg(_manager_lock);
_is_leader[group_id] = false;
Expand All @@ -167,7 +167,7 @@ void ManagerImpl::exit_group(group_id_t const& group_id) {
nuraft::cmd_result_code ManagerImpl::group_init(int32_t const srv_id, group_id_t const& group_id,
group_type_t const& group_type, nuraft::context*& ctx,
std::shared_ptr< nuraft_mesg::group_metrics > metrics) {
LOGDEBUGMOD(nuraft_mesg, "Creating context for Group: {} as Member: {}", group_id, srv_id);
LOGDEBUGMOD(nuraft_mesg, "Creating context for: [group_id={}] as Member: {}", group_id, srv_id);

// State manager (RAFT log store, config)
std::shared_ptr< nuraft::state_mgr > smgr;
Expand All @@ -185,7 +185,7 @@ nuraft::cmd_result_code ManagerImpl::group_init(int32_t const srv_id, group_id_t
if (it != _state_managers.end()) {
if (happened) {
// A new logstore!
LOGDEBUGMOD(nuraft_mesg, "Creating new State Manager for: {}, type: {}", group_id, group_type);
LOGDEBUGMOD(nuraft_mesg, "Creating new State Manager for: [group={}], type: {}", group_id, group_type);
it->second = application_.lock()->create_state_mgr(srv_id, group_id);
}
it->second->become_ready();
Expand Down Expand Up @@ -327,11 +327,11 @@ NullAsyncResult ManagerImpl::become_leader(group_id_t const& group_id) {
}

void ManagerImpl::leave_group(group_id_t const& group_id) {
LOGINFO("Leaving group [vol={}]", group_id);
LOGINFO("Leaving group [group={}]", group_id);
{
std::lock_guard< std::mutex > lg(_manager_lock);
if (0 == _state_managers.count(group_id)) {
LOGDEBUGMOD(nuraft_mesg, "Asked to leave group {} which we are not part of!", group_id);
LOGDEBUGMOD(nuraft_mesg, "Asked to leave [group={}] which we are not part of!", group_id);
return;
}
}
Expand All @@ -345,7 +345,7 @@ void ManagerImpl::leave_group(group_id_t const& group_id) {
_state_managers.erase(it);
}

LOGINFO("Finished leaving: [vol={}]", group_id);
LOGINFO("Finished leaving: [group={}]", group_id);
}

uint32_t ManagerImpl::logstore_id(group_id_t const& group_id) const {
Expand Down

0 comments on commit 74d9702

Please sign in to comment.