65 lines
2.1 KiB
C++
65 lines
2.1 KiB
C++
#include "init_spark_lib.h"
|
|
#include "spark/config/spark_data_directory.h"
|
|
#include "spark/utils/thread_manager.h"
|
|
#include "system/logging/logging.h"
|
|
#include "system/output_switch.h"
|
|
#include "system/protobufs/logging.pb.h"
|
|
|
|
namespace bts {
|
|
namespace utils {
|
|
|
|
using bts::logging::LoggingConfigPoller;
|
|
using bts::system::threading::ThreadManager;
|
|
|
|
static LoggingConfigPoller *poller = nullptr;
|
|
|
|
static void init_spark_lib(
|
|
std::optional<logging::protobufs::Logging> logging_cfg,
|
|
bool hot_reload,
|
|
bool quiet_console) {
|
|
system::OutputSwitch cout{&std::cout, quiet_console};
|
|
// Write to stdout instead of normal log, because the logging system hasn't
|
|
// been configured yet (that's one of the things we're about to do).
|
|
cout << "Initializing spark_lib\n";
|
|
cout << "Configuring thread 'main'" << std::endl;
|
|
threading::configure_current_thread("main");
|
|
cout << "Starting default logging thread" << std::endl;
|
|
logging::start_default_logging_thread();
|
|
cout << "Initializing LoggingConfigPoller" << std::endl;
|
|
ThreadManager thread_man{ThreadManager::default_thread_config()};
|
|
const auto logger_thread_cfg = thread_man.get_thread_cfg("logger");
|
|
if (!logging_cfg) {
|
|
logging_cfg = config::get<logging::protobufs::Logging>();
|
|
}
|
|
const spark::SparkDataDirectory data_dir;
|
|
if (hot_reload) {
|
|
poller = new LoggingConfigPoller(
|
|
*logging_cfg, thread_man.get_thread_cfg("logger"),
|
|
data_dir.log_file().string(), data_dir.log_cache_file().string());
|
|
} else {
|
|
logging::configure_logging(
|
|
*logging_cfg, logger_thread_cfg, data_dir.log_file().string());
|
|
}
|
|
}
|
|
|
|
SparkLibInit::SparkLibInit(
|
|
std::optional<logging::protobufs::Logging> logging_cfg,
|
|
bool hot_reload,
|
|
bool quiet_console) {
|
|
init_spark_lib(logging_cfg, hot_reload, quiet_console);
|
|
}
|
|
|
|
SparkLibInit::~SparkLibInit() { finit_spark_lib(); }
|
|
|
|
void init_spark_lib() { init_spark_lib(std::nullopt, true, false); }
|
|
|
|
void finit_spark_lib() {
|
|
LOG(Gen, Diag, "finit_spark_lib");
|
|
if (poller) {
|
|
delete poller;
|
|
}
|
|
}
|
|
|
|
} // namespace utils
|
|
} // namespace bts
|