|
| 1 | +#include <csignal> |
| 2 | +#include <cstdlib> |
| 3 | +#include <exception> |
| 4 | +#include <iostream> |
| 5 | +#include <new> |
1 | 6 | #include <string> |
2 | 7 |
|
3 | 8 | #include "binance/config.h" |
|
6 | 11 | #include "spdlog/sinks/basic_file_sink.h" |
7 | 12 | #include "spdlog/spdlog.h" |
8 | 13 | #include "ui/app/ui_app.h" |
| 14 | +#include "utils/crash.h" |
9 | 15 | #include "utils/env.h" |
10 | 16 | #include "utils/threading.h" |
11 | 17 |
|
12 | 18 | int main() { |
13 | | - utils::Threading::set_thread_name("main"); |
| 19 | + try { |
| 20 | + utils::Threading::set_thread_name("main"); |
14 | 21 |
|
15 | | - // log config |
16 | | - spdlog::cfg::load_env_levels("LOG_LEVEL"); |
17 | | - const char* log_path = std::getenv("LOG_PATH"); |
18 | | - const auto logger = spdlog::basic_logger_mt("basic_logger", log_path); |
19 | | - spdlog::set_default_logger(logger); |
20 | | - // Set a global pattern without the logger name |
21 | | - spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [%t] %v"); |
22 | | - spdlog::flush_every(std::chrono::microseconds(100)); |
23 | | - spdlog::info("hello"); |
24 | | - utils::Env::log_current_architecture(); |
| 22 | + // log config |
| 23 | + spdlog::cfg::load_env_levels("LOG_LEVEL"); |
| 24 | + const char* log_path = std::getenv("LOG_PATH"); |
| 25 | + const auto logger = spdlog::basic_logger_mt("basic_logger", log_path); |
| 26 | + spdlog::set_default_logger(logger); |
| 27 | + // Set a global pattern without the logger name |
| 28 | + spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [%t] %v"); |
| 29 | + spdlog::flush_every(std::chrono::microseconds(100)); |
| 30 | + spdlog::info("hello"); |
| 31 | + utils::Env::log_current_architecture(); |
25 | 32 |
|
26 | | - // Binance market data connectivity |
27 | | - auto b_conf = binance::Config::from_env(); |
28 | | - auto b_worker = binance::Worker::from_conf(b_conf); |
29 | | - b_worker.start(); |
| 33 | + // configure error-handling |
| 34 | + utils::Crash::setup_crash_handlers(); |
30 | 35 |
|
31 | | - // ui app (reads from Binance's queues) |
32 | | - auto ui = |
33 | | - ui::App::from_env(b_worker.get_order_queue(), b_worker.get_trade_queue(), b_conf); |
34 | | - ui.start(); |
| 36 | + // Binance market data connectivity |
| 37 | + auto b_conf = binance::Config::from_env(); |
| 38 | + auto b_worker = binance::Worker::from_conf(b_conf); |
| 39 | + b_worker.start(); |
35 | 40 |
|
36 | | - if (ui.thread_exception) { |
37 | | - std::rethrow_exception(ui.thread_exception); |
| 41 | + // ui app (reads from Binance's queues) |
| 42 | + auto ui = |
| 43 | + ui::App::from_env(b_worker.get_order_queue(), b_worker.get_trade_queue(), b_conf); |
| 44 | + // blocking |
| 45 | + ui.start(); |
| 46 | + |
| 47 | + if (ui.thread_exception) { |
| 48 | + std::rethrow_exception(ui.thread_exception); |
| 49 | + } |
| 50 | + b_worker.stop(); |
| 51 | + spdlog::info("goodbye"); |
| 52 | + } catch (const std::exception& e) { |
| 53 | + spdlog::error("[EXCEPTION] Caught exception. ex [{}]", e.what()); |
| 54 | + } catch (...) { |
| 55 | + spdlog::error("[EXCEPTION] Caught unknown exception"); |
38 | 56 | } |
39 | | - b_worker.stop(); |
40 | | - spdlog::info("goodbye"); |
41 | 57 | } |
0 commit comments