Replace printf logging with spdlog equivalent

Preserve previous printfs in comments for now. Spdlog needs to be configured to be thread-safe. Few additional printfs to convert later. No changes have been made to GOAL's internal printing system
This commit is contained in:
Shay
2020-10-01 16:08:23 -06:00
parent 4d208b0729
commit e2ea57ea58
13 changed files with 131 additions and 60 deletions
+13 -6
View File
@@ -13,7 +13,8 @@
*/
SystemThread& SystemThreadManager::create_thread(const std::string& name) {
if (thread_count >= MAX_SYSTEM_THREADS) {
throw std::runtime_error("Out of System Threads! Please increase MAX_SYSTEM_THREADS");
spdlog::critical("Out of System Threads! MAX_SYSTEM_THREADS is ", MAX_SYSTEM_THREADS);
throw std::runtime_error("Out of System Threads! Please increase MAX_SYSTEM_THREADS");
}
auto& thread = threads[thread_count];
@@ -49,7 +50,8 @@ void SystemThreadManager::print_stats() {
*/
void SystemThreadManager::shutdown() {
for (int i = 0; i < thread_count; i++) {
printf("# Stop %s\n", threads[i].name.c_str());
//printf("# Stop %s\n", threads[i].name.c_str());
spdlog::debug("# Stop {}", threads[i].name.c_str());
threads[i].stop();
}
}
@@ -59,7 +61,8 @@ void SystemThreadManager::shutdown() {
*/
void SystemThreadManager::join() {
for (int i = 0; i < thread_count; i++) {
printf("# Join %s\n", threads[i].name.c_str());
//printf("# Join %s\n", threads[i].name.c_str());
spdlog::debug(" # Join {}", threads[i].name.c_str());
if (threads[i].running) {
threads[i].join();
}
@@ -73,7 +76,8 @@ void* bootstrap_thread_func(void* x) {
SystemThread* thd = (SystemThread*)x;
SystemThreadInterface iface(thd);
thd->function(iface);
printf("[SYSTEM] Thread %s is returning\n", thd->name.c_str());
//printf("[SYSTEM] Thread %s is returning\n", thd->name.c_str());
spdlog::debug("[SYSTEM] Thread {} is returning", thd->name.c_str());
return nullptr;
}
@@ -81,7 +85,9 @@ void* bootstrap_thread_func(void* x) {
* Start a thread and wait for its initialization
*/
void SystemThread::start(std::function<void(SystemThreadInterface&)> f) {
printf("# Initialize %s...\n", name.c_str());
//printf("# Initialize %s...\n", name.c_str());
spdlog::debug("# Initialize {}...", name.c_str());
function = f;
thread = std::thread(bootstrap_thread_func, this);
running = true;
@@ -118,7 +124,8 @@ void SystemThreadInterface::initialization_complete() {
std::unique_lock<std::mutex> mlk(thread.initialization_mutex);
thread.initialization_complete = true;
thread.initialization_cv.notify_all();
printf("# %s initialized\n", thread.name.c_str());
//printf("# %s initialized\n", thread.name.c_str());
spdlog::debug("# {} initialized", thread.name.c_str());
}
/*!