Skip to content

Commit

Permalink
fix: crash when app exits
Browse files Browse the repository at this point in the history
  • Loading branch information
Serein207 committed Jul 30, 2024
1 parent 35aff8a commit 667cfea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/Infrastructure/Network/network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/signal_set.hpp>
#include <sast_link.h>
#include <thread>

Expand All @@ -21,6 +22,8 @@ void start_sast_link() {
}
},
net::detached);
net::signal_set signals{ioc, SIGINT, SIGTERM};
signals.async_wait([&ioc](auto, auto) { ioc.stop(); });
ioc.run();
}};
t.detach();
Expand Down
27 changes: 9 additions & 18 deletions src/Infrastructure/Utils/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
class Logger {
public:
using Level = spdlog::level::level_enum;
static Logger* getInstance() {
static Logger s_instance;
return &s_instance;
}
void initLogger(Level level,
const std::string& filepath,
std::size_t q_max_items,
std::size_t thread_count) {
Logger(Level level,
const std::string& filepath,
std::size_t q_max_items = 8192,
std::size_t thread_count = 1) {
spdlog::file_event_handlers handlers;
handlers.after_open = [](spdlog::filename_t filename, std::FILE* fstream) {
fputs("[Start SAST-Evento-Desktop]\n", fstream);
Expand All @@ -37,7 +33,6 @@ class Logger {
#ifdef EVENTO_RELEASE
stdoutSink->set_level(Level::off);
#endif

_asyncLogger->set_level(level);
_asyncLogger->set_error_handler(
[&](const std::string& msg) { _asyncLogger->error("*** LOGGER ERROR ***: {}", msg); });
Expand All @@ -49,18 +44,14 @@ class Logger {
stdoutSink->set_pattern("\033[36m[%Y-%m-%d %H:%M:%S.%e] \033[92m[%n] \033[0m%^[%l]%$ %v");
spdlog::set_default_logger(_asyncLogger);
}
auto getLogger() { return _asyncLogger; }
Level getLogLevel() const { return _asyncLogger->level(); }
auto& logger() { return _asyncLogger; }
[[nodiscard]] Level logLevel() const { return _asyncLogger->level(); }
void setLogLevel(Level level) { _asyncLogger->set_level(level); }
~Logger() {
// spdlog::drop("evento-logger");
spdlog::shutdown();
}
Logger(const Logger&) = delete;
Logger& operator=(const Logger&) = delete;
~Logger() { spdlog::shutdown(); }

private:
Logger() = default;
Logger(const Logger&) = delete;
Logger& operator==(const Logger&) = delete;
std::shared_ptr<spdlog::async_logger> _asyncLogger;
std::shared_ptr<spdlog::details::thread_pool> _threadPool;
};
5 changes: 3 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <Infrastructure/Network/network.h>
#include <Infrastructure/Utils/Logger.h>
#include <Version.h>
#include <app.h>
#include <spdlog/spdlog.h>

int main(int argc, char** argv) {
Logger logger;
logger.initLogger(Logger::Level::debug, "logs/evento.log", 8192, 1);
Logger logger(Logger::Level::debug, "logs/evento.log");
spdlog::info("SAST Evento version: v" VERSION_FULL);
auto ui = App::create();
ui->on_loginClicked(start_sast_link);
Expand Down

0 comments on commit 667cfea

Please sign in to comment.