diff --git a/moon-src/core/log.hpp b/moon-src/core/log.hpp index 9e881bdc..2da0febb 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 c949a40d..a439a7f2 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 62d5c328..6b6f9890 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 dfacd309..15314a1e 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()); }