diff --git a/src/core/app.cpp b/src/core/app.cpp index d973ffc..40c0ae6 100644 --- a/src/core/app.cpp +++ b/src/core/app.cpp @@ -89,7 +89,12 @@ bool fastweb::app::start(const std::string& config_filepath) this->subscribe->start(); - return m_center->start(); + if (m_center->start()) + { + m_lastErrorDesc = m_center->last_error(); + return false; + } + return true; } void fastweb::app::stop() diff --git a/src/core/entry.cpp b/src/core/entry.cpp index 297b34a..f41c6ce 100644 --- a/src/core/entry.cpp +++ b/src/core/entry.cpp @@ -13,7 +13,9 @@ extern "C" { fastweb::app* app = new fastweb::app(); if (app->start(config_filepath) == false) { + app->log->error("fastweb start failed," + app->last_error(), __FILE__, __func__, __LINE__); + app->log->write(); delete app; return nullptr; } diff --git a/src/core/log.cpp b/src/core/log.cpp index 84445d7..f33f912 100644 --- a/src/core/log.cpp +++ b/src/core/log.cpp @@ -46,29 +46,10 @@ bool fastweb::log::run() ITHREAD_WAIT_MSEC(1000); return true; } - std::string logcontent; - std::string new_time = time::now_time(app()->config->log.name); - if (new_time == "") - { - std::cout << "error: The log file name is incorrect: " << app()->config->log.name << std::endl; + + if (write() == false) return false; - } - if (m_current_name != new_time) - { - m_current_name = new_time; - ylib::file::create_dir(app()->config->log.dir, true); - std::string newfilepath = app()->config->log.dir + "/" + new_time; - m_file.close(); - if (m_file.open(newfilepath) == false) - { - std::cout << "error: open log file failed, filepath: " << newfilepath << std::endl; - return false; - } - } - while (m_queue.pop(logcontent)) - { - m_file.appead(logcontent); - } + ITHREAD_WAIT_MSEC(1000); return true; } @@ -133,3 +114,31 @@ void fastweb::log::lua(const std::string& msg) { this->print("[LUA ] ", msg,"","",0, ylib::ConsoleTextColor::GREEN | ylib::ConsoleTextColor::RED | ylib::ConsoleTextColor::BLUE, false); } + +bool fastweb::log::write() +{ + std::string logcontent; + std::string new_time = time::now_time(app()->config->log.name); + if (new_time == "") + { + std::cout << "error: The log file name is incorrect: " << app()->config->log.name << std::endl; + return false; + } + if (m_current_name != new_time) + { + m_current_name = new_time; + ylib::file::create_dir(app()->config->log.dir, true); + std::string newfilepath = app()->config->log.dir + "/" + new_time; + m_file.close(); + if (m_file.open(newfilepath) == false) + { + std::cout << "error: open log file failed, filepath: " << newfilepath << std::endl; + return false; + } + } + while (m_queue.pop(logcontent)) + { + m_file.appead(logcontent); + } + return true; +} diff --git a/src/core/log.h b/src/core/log.h index 6f09736..c6cfff5 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -17,6 +17,8 @@ namespace fastweb void warn(const std::string& msg, const std::string& filepath, const std::string& func, int line); void debug(const std::string& msg, const std::string& filepath, const std::string& func, int line); void lua(const std::string& msg); + + bool write(); private: void print(const std::string& type, const std::string& msg, const std::string& filepath, const std::string& func, int line, int color, bool error); bool run() override;