Skip to content

Commit

Permalink
Fixed the issue of an exception being thrown during initialization, c…
Browse files Browse the repository at this point in the history
…ausing the process to hang
  • Loading branch information
sniper00 committed Jul 19, 2024
1 parent 09fadf2 commit 79d7f35
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions moon-src/core/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ namespace moon
state_.store(state::ready, std::memory_order_release);
}

bool is_ready() const
{
return state_.load(std::memory_order_acquire) == state::ready;
}

template<typename... Args>
void logfmt(bool console, LogLevel level, const char* fmt, Args&&... args)
{
Expand Down
4 changes: 2 additions & 2 deletions moon-src/core/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace moon
}
else
{
auto content = moon::format("remove_service: invalid service id %u.", serviceid);
auto content = moon::format("server::remove_service invalid service id %u.", serviceid);
response(sender, content, sessionid, PTYPE_ERROR);
}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ namespace moon
{
if (get_state() == state::ready && mtype == PTYPE_ERROR && !content.empty())
{
CONSOLE_DEBUG("server::response %s" , std::string(content).data());
CONSOLE_DEBUG("%s" , std::string(content).data());
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion moon-src/core/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace moon
}
else
{
server_->response(sender, moon::format("service [%08X] not found", serviceid), sessionid, PTYPE_ERROR);
server_->response(sender, moon::format("worker::remove_service [%08X] not found", serviceid), sessionid, PTYPE_ERROR);
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions moon-src/moon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ int main(int argc, char* argv[])
}
catch (const std::exception& e)
{
if (!log::instance().is_ready()) {
log::instance().init("");
}
exitcode = -1;
CONSOLE_ERROR("ERROR:%s", e.what());
}
Expand Down

0 comments on commit 79d7f35

Please sign in to comment.