diff --git a/lib/include/srslte/common/test_common.h b/lib/include/srslte/common/test_common.h index 6003fd8eb..1c2e720b5 100644 --- a/lib/include/srslte/common/test_common.h +++ b/lib/include/srslte/common/test_common.h @@ -252,7 +252,7 @@ private: } \ } while (0) -#define TESTASSERT(cond) CONDERROR((not(cond)), "[%s][Line %d] Fail at \"%s\"\n", __FUNCTION__, __LINE__, (#cond)) +#define TESTASSERT(cond) CONDERROR((not(cond)), "[%s][Line %d] Fail at \"%s\"", __FUNCTION__, __LINE__, (#cond)) #else // if C diff --git a/lib/include/srslte/common/time_prof.h b/lib/include/srslte/common/time_prof.h index e70d5cafc..f34d2819f 100644 --- a/lib/include/srslte/common/time_prof.h +++ b/lib/include/srslte/common/time_prof.h @@ -48,8 +48,7 @@ class tprof public: template explicit tprof(Args&&... args) : prof(std::forward(args)...) - { - } + {} void start() { meas.start(); } @@ -71,8 +70,7 @@ class tprof public: template explicit tprof(Args&&... args) - { - } + {} void start() {} @@ -106,8 +104,7 @@ struct mutexed_tprof { template explicit mutexed_tprof(Args&&... args) : prof(std::forward(args)...) - { - } + {} measure start() { return measure{this}; } Prof prof; @@ -126,8 +123,7 @@ struct mutexed_tprof { template explicit mutexed_tprof(Args&&... args) - { - } + {} measure start() { return measure{}; } }; @@ -135,11 +131,11 @@ struct avg_time_stats { avg_time_stats(const char* name_, const char* logname, size_t print_period_); void operator()(std::chrono::nanoseconds duration); - srslte::log_ref log_ptr; - std::string name; - double avg_val = 1; - long count = 0, max_val = 0, min_val = std::numeric_limits::max(); - long print_period = 0; + srslog::basic_logger& logger; + std::string name; + double avg_val = 1; + long count = 0, max_val = 0, min_val = std::numeric_limits::max(); + long print_period = 0; }; template @@ -149,7 +145,7 @@ public: sliding_window_stats(const char* name_, const char* logname, size_t print_period_ = 10); void operator()(std::chrono::nanoseconds duration); - srslte::log_ref log_ptr; + srslog::basic_logger& logger; std::string name; std::vector sliding_window; size_t window_idx = 0; diff --git a/lib/include/srslte/common/timers.h b/lib/include/srslte/common/timers.h index 7c0b0fce1..118f581a7 100644 --- a/lib/include/srslte/common/timers.h +++ b/lib/include/srslte/common/timers.h @@ -64,11 +64,11 @@ class timer_handler bool set(uint32_t duration_) { if (duration_ > MAX_TIMER_DURATION) { - ERROR("Error: timer durations above %u are not supported\n", MAX_TIMER_DURATION); + ERROR("Error: timer durations above %u are not supported", MAX_TIMER_DURATION); return false; } if (not active) { - ERROR("Error: setting inactive timer id=%d\n", id()); + ERROR("Error: setting inactive timer id=%d", id()); return false; } duration = duration_; @@ -92,7 +92,7 @@ class timer_handler { std::unique_lock lock(parent->mutex); if (not active) { - ERROR("Error: calling run() for inactive timer id=%d\n", id()); + ERROR("Error: calling run() for inactive timer id=%d", id()); return; } timeout = parent->cur_time + duration; diff --git a/lib/include/srslte/common/tti_point.h b/lib/include/srslte/common/tti_point.h index 0f2db24f7..3e4fcf3ae 100644 --- a/lib/include/srslte/common/tti_point.h +++ b/lib/include/srslte/common/tti_point.h @@ -30,7 +30,7 @@ struct tti_point { if (diff < 10240) { tti_val = 10240 - diff - 1; } else { - srslte::logmap::get("COMMON")->error("Invalid TTI point assigned\n"); + srslog::fetch_basic_logger("COMMON").error("Invalid TTI point assigned"); } } } diff --git a/lib/src/common/test/thread_pool_test.cc b/lib/src/common/test/thread_pool_test.cc index d6817cbee..b95d409f2 100644 --- a/lib/src/common/test/thread_pool_test.cc +++ b/lib/src/common/test/thread_pool_test.cc @@ -21,21 +21,21 @@ class dummy_radio private: static const int radio_delay_us = 200; - srslte::log_filter* log_h = nullptr; - std::mutex mutex; + srslog::basic_logger& logger; + std::mutex mutex; uint32_t last_tti = 0; bool first = true; bool late = false; public: - dummy_radio(srslte::log_filter& log_h_) : log_h(&log_h_) { log_h->info("Dummy radio created\n"); } + explicit dummy_radio(srslog::basic_logger& logger) : logger(logger) { logger.info("Dummy radio created"); } void tx(uint32_t tti) { std::lock_guard lock(mutex); - log_h->info("Transmitting TTI %d\n", tti); + logger.info("Transmitting TTI %d", tti); // Exit if TTI was advanced if (!first && tti <= last_tti) { @@ -59,8 +59,8 @@ private: static const int sleep_time_min_us = 50; static const int sleep_time_max_us = 2000; + srslog::basic_logger& logger; srslte::tti_semaphore* tti_semaphore = nullptr; - srslte::log_filter* log_h = nullptr; dummy_radio* radio = nullptr; srslte_random_t random_gen = nullptr; uint32_t tti = 0; @@ -68,14 +68,14 @@ private: public: dummy_worker(uint32_t id, srslte::tti_semaphore* tti_semaphore_, - srslte::log_filter* log_h_, - dummy_radio* radio_) + srslog::basic_logger& logger, + dummy_radio* radio_) : + logger(logger) { tti_semaphore = tti_semaphore_; - log_h = log_h_; radio = radio_; random_gen = srslte_random_init(id); - log_h->info("Dummy worker created\n"); + logger.info("Dummy worker created"); } ~dummy_worker() { srslte_random_free(random_gen); } @@ -91,9 +91,9 @@ protected: // Inform // Actual work ;) - log_h->info("Start working for %d us.\n", sleep_time_us); + logger.info("Start working for %d us.", sleep_time_us); usleep(sleep_time_us); - log_h->info("Stopped working\n"); + logger.info("Stopped working"); // Wait for green light tti_semaphore->wait(tti); @@ -121,28 +121,15 @@ int main(int argc, char** argv) std::vector > workers; srslte::tti_semaphore tti_semaphore; - // Setup logging. - srslog::sink* s = srslog::create_stdout_sink(); - if (!s) { - return SRSLTE_ERROR; - } - srslog::log_channel* chan = srslog::create_log_channel("main_channel", *s); - if (!chan) { - return SRSLTE_ERROR; - } - srslte::srslog_wrapper logger(*chan); + // Loggers. + auto& radio_logger = srslog::fetch_basic_logger("radio", false); + radio_logger.set_level(srslog::basic_levels::none); // Start the log backend. srslog::init(); - // Loggers - srslte::log_filter radio_log("radio", &logger); - std::vector > worker_logs; - - radio_log.set_level("none"); - // Radio - dummy_radio radio(radio_log); + dummy_radio radio(radio_logger); // Create workers for (uint32_t i = 0; i < nof_workers; i++) { @@ -150,15 +137,13 @@ int main(int argc, char** argv) char log_name[32] = {}; snprintf(log_name, sizeof(log_name), "PHY%d", i); - // Create log filter - srslte::log_filter* log_filter = new srslte::log_filter(log_name, &logger); - log_filter->set_level("none"); + auto& logger = srslog::fetch_basic_logger(log_name, false); + logger.set_level(srslog::basic_levels::none); // Create worker - auto* worker = new dummy_worker(i, &tti_semaphore, log_filter, &radio); + auto* worker = new dummy_worker(i, &tti_semaphore, logger, &radio); // Push back objects - worker_logs.push_back(std::unique_ptr(log_filter)); workers.push_back(std::unique_ptr(worker)); // Init worker in pool diff --git a/lib/src/common/threads.c b/lib/src/common/threads.c index 8d37a6406..8c4951a53 100644 --- a/lib/src/common/threads.c +++ b/lib/src/common/threads.c @@ -59,7 +59,7 @@ bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void* } if (pthread_attr_setschedparam(&attr, ¶m)) { perror("pthread_attr_setschedparam"); - ERROR("Error not enough privileges to set Scheduling priority\n"); + ERROR("Error not enough privileges to set Scheduling priority"); } attr_enable = true; } else if (prio_offset == -1) { @@ -73,7 +73,7 @@ bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void* } if (pthread_attr_setschedparam(&attr, ¶m)) { perror("pthread_attr_setschedparam"); - ERROR("Error not enough privileges to set Scheduling priority\n"); + ERROR("Error not enough privileges to set Scheduling priority"); } attr_enable = true; } else if (prio_offset == -2) { diff --git a/lib/src/common/time_prof.cc b/lib/src/common/time_prof.cc index 67ee05f2f..12b495273 100644 --- a/lib/src/common/time_prof.cc +++ b/lib/src/common/time_prof.cc @@ -54,11 +54,8 @@ const char* get_tunit_str() // tprof stats avg_time_stats::avg_time_stats(const char* name_, const char* logname, size_t print_period_) : - name(name_), - log_ptr(srslte::logmap::get(logname)), - print_period(print_period_) -{ -} + name(name_), logger(srslog::fetch_basic_logger(logname)), print_period(print_period_) +{} void avg_time_stats::operator()(nanoseconds duration) { @@ -67,22 +64,19 @@ void avg_time_stats::operator()(nanoseconds duration) max_val = std::max(max_val, duration.count()); min_val = std::min(min_val, duration.count()); if (count % print_period == 0) { - log_ptr->info("%s: {mean, max, min}={%0.1f, %ld, %ld} usec, nof_samples=%ld", - name.c_str(), - avg_val / 1e3, - max_val / 1000, - min_val / 1000, - count); + logger.info("%s: {mean, max, min}={%0.1f, %ld, %ld} usec, nof_samples=%ld", + name.c_str(), + avg_val / 1e3, + max_val / 1000, + min_val / 1000, + count); } } template sliding_window_stats::sliding_window_stats(const char* name_, const char* logname, size_t print_period_) : - name(name_), - log_ptr(srslte::logmap::get(logname)), - sliding_window(print_period_) -{ -} + name(name_), logger(srslog::fetch_basic_logger(logname)), sliding_window(print_period_) +{} template void sliding_window_stats::operator()(nanoseconds duration) @@ -91,7 +85,7 @@ void sliding_window_stats::operator()(nanoseconds duration) const char* unit_str = get_tunit_str(); TUnit dur = std::chrono::duration_cast(duration); - log_ptr->debug("%s: duration=%" PRId64 " %s\n", name.c_str(), dur.count(), unit_str); + logger.debug("%s: duration=%" PRId64 " %s", name.c_str(), dur.count(), unit_str); sliding_window[window_idx++] = duration; if (window_idx == sliding_window.size()) { @@ -100,12 +94,12 @@ void sliding_window_stats::operator()(nanoseconds duration) nanoseconds tmin = *std::min_element(sliding_window.begin(), sliding_window.end()); double tmean = static_cast(duration_cast(tsum).count()) / sliding_window.size(); - log_ptr->info("%s: {mean, max, min} = {%0.2f, %" PRId64 ", %" PRId64 "} %s\n", - name.c_str(), - tmean, - duration_cast(tmax).count(), - duration_cast(tmin).count(), - unit_str); + logger.info("%s: {mean, max, min} = {%0.2f, %" PRId64 ", %" PRId64 "} %s", + name.c_str(), + tmean, + duration_cast(tmax).count(), + duration_cast(tmin).count(), + unit_str); window_idx = 0; } } diff --git a/lib/test/common/tti_point_test.cc b/lib/test/common/tti_point_test.cc index 6e472cdd4..4e671e57c 100644 --- a/lib/test/common/tti_point_test.cc +++ b/lib/test/common/tti_point_test.cc @@ -68,6 +68,7 @@ int test_tti_type() int main() { + srslog::init(); TESTASSERT(test_tti_type() == SRSLTE_SUCCESS); return 0; }