From 79d7f354c906045c8262c909f90758dcf1fb9ba0 Mon Sep 17 00:00:00 2001 From: Bruce Date: Fri, 19 Jul 2024 22:29:19 +0800 Subject: [PATCH] Fixed the issue of an exception being thrown during initialization, causing the process to hang --- moon-src/core/log.hpp | 5 +++++ moon-src/core/server.cpp | 4 ++-- moon-src/core/worker.cpp | 2 +- moon-src/moon.cpp | 3 +++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/moon-src/core/log.hpp b/moon-src/core/log.hpp index 9e881bdce..2da0febba 100644 --- a/moon-src/core/log.hpp +++ b/moon-src/core/log.hpp @@ -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 void logfmt(bool console, LogLevel level, const char* fmt, Args&&... args) { diff --git a/moon-src/core/server.cpp b/moon-src/core/server.cpp index c949a40d8..a439a7f26 100644 --- a/moon-src/core/server.cpp +++ b/moon-src/core/server.cpp @@ -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); } } @@ -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; } diff --git a/moon-src/core/worker.cpp b/moon-src/core/worker.cpp index 62d5c3282..6b6f9890a 100644 --- a/moon-src/core/worker.cpp +++ b/moon-src/core/worker.cpp @@ -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); } }); } diff --git a/moon-src/moon.cpp b/moon-src/moon.cpp index dfacd3092..15314a1e3 100644 --- a/moon-src/moon.cpp +++ b/moon-src/moon.cpp @@ -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()); }