diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index ccf1dd637..7c46bfc26 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -35,7 +35,7 @@ #include "srslte/common/log.h" #include "srslte/common/logger.h" -#include "srslte/common/logger_stdout.h" +#include "srslte/common/logger_srslog_wrapper.h" #include "srslte/phy/common/timestamp.h" namespace srslte { @@ -75,16 +75,15 @@ public: void set_time_src(time_itf* source, time_format_t format); protected: - logger* logger_h; - bool do_tti; + std::unique_ptr default_logger; + logger* logger_h; + bool do_tti; static const int char_buff_size = logger::preallocated_log_str_size - 64 * 3; time_itf* time_src; time_format_t time_format; - logger_stdout def_logger_stdout; - void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, const char* msg, diff --git a/lib/include/srslte/common/logger_file.h b/lib/include/srslte/common/logger_file.h deleted file mode 100644 index ceb9f7f7a..000000000 --- a/lib/include/srslte/common/logger_file.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2013-2020 Software Radio Systems Limited - * - * This file is part of srsLTE. - * - * srsLTE is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * srsLTE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * A copy of the GNU Affero General Public License can be found in - * the LICENSE file in the top-level directory of this distribution - * and at http://www.gnu.org/licenses/. - * - */ - -/****************************************************************************** - * File: logger_file.h - * Description: Common log object. Maintains a queue of log messages - * and runs a thread to read messages and write to file. - * Multiple producers, single consumer. If full, producers - * increase queue size. If empty, consumer blocks. - *****************************************************************************/ - -#ifndef SRSLTE_LOGGER_FILE_H -#define SRSLTE_LOGGER_FILE_H - -#include "srslte/common/logger.h" -#include "srslte/common/threads.h" -#include -#include -#include - -namespace srslte { - -typedef std::string* str_ptr; - -class logger_file : public thread, public logger -{ -public: - logger_file(); - logger_file(std::string file); - ~logger_file(); - void init(std::string file, int max_length = -1); - void stop(); - // Implementation of log_out - void log(unique_log_str_t msg); - -private: - void run_thread(); - void flush(); - - uint32_t name_idx; - int64_t max_length; - int64_t cur_length; - FILE* logfile; - bool is_running; - std::string filename; - pthread_cond_t not_empty; - pthread_mutex_t mutex; - - std::deque buffer; -}; - -} // namespace srslte - -#endif // SRSLTE_LOGGER_FILE_H diff --git a/lib/include/srslte/common/logger_stdout.h b/lib/include/srslte/common/logger_stdout.h deleted file mode 100644 index 6ca985a52..000000000 --- a/lib/include/srslte/common/logger_stdout.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013-2020 Software Radio Systems Limited - * - * This file is part of srsLTE. - * - * srsLTE is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * srsLTE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * A copy of the GNU Affero General Public License can be found in - * the LICENSE file in the top-level directory of this distribution - * and at http://www.gnu.org/licenses/. - * - */ - -/****************************************************************************** - * File: logger_stdout.h - * Description: Interface for logging output - *****************************************************************************/ - -#ifndef SRSLTE_LOGGER_STDOUT_H -#define SRSLTE_LOGGER_STDOUT_H - -#include "srslte/common/logger.h" -#include -#include - -namespace srslte { - -class logger_stdout : public logger -{ -public: - void log(unique_log_str_t log_str) { fprintf(stdout, "%s", log_str->str()); } -}; - -} // namespace srslte - -#endif // SRSLTE_LOGGER_STDOUT_H diff --git a/lib/include/srslte/common/logmap.h b/lib/include/srslte/common/logmap.h index 4ddc50df4..05ad11785 100644 --- a/lib/include/srslte/common/logmap.h +++ b/lib/include/srslte/common/logmap.h @@ -24,8 +24,10 @@ #include "srslte/common/log.h" #include "srslte/common/logger.h" +#include "srslte/common/logger_srslog_wrapper.h" #include "srslte/common/singleton.h" +#include #include #include @@ -85,13 +87,11 @@ protected: private: log_ref get_impl(std::string servicename); - // consts - std::unique_ptr logger_stdout_val; - // default cfg - logger* default_logger = nullptr; - srslte::LOG_LEVEL_ENUM default_log_level = LOG_LEVEL_WARNING; - int default_hex_limit = 1024; + std::unique_ptr stdout_channel; + logger* default_logger = nullptr; + srslte::LOG_LEVEL_ENUM default_log_level = LOG_LEVEL_WARNING; + int default_hex_limit = 1024; // state std::mutex mutex; diff --git a/lib/include/srslte/common/signal_handler.h b/lib/include/srslte/common/signal_handler.h index 378cff36c..13dde1f8b 100644 --- a/lib/include/srslte/common/signal_handler.h +++ b/lib/include/srslte/common/signal_handler.h @@ -27,7 +27,6 @@ #ifndef SRSLTE_SIGNAL_HANDLER_H #define SRSLTE_SIGNAL_HANDLER_H -#include "srslte/common/logger_file.h" #include "srslte/srslog/sink.h" #include #include @@ -40,7 +39,6 @@ extern "C" { // static vars required by signal handling static srslog::sink* log_sink = nullptr; -static srslte::logger_file logger_file; static bool running = true; static void srslte_signal_handler(int signal) @@ -49,7 +47,6 @@ static void srslte_signal_handler(int signal) case SIGALRM: fprintf(stderr, "Couldn't stop after %ds. Forcing exit.\n", SRSLTE_TERM_TIMEOUT_S); //:TODO: refactor the sighandler, should not depend on log utilities - logger_file.stop(); if (log_sink) { log_sink->flush(); } diff --git a/lib/src/common/CMakeLists.txt b/lib/src/common/CMakeLists.txt index 49e168941..c97b6250b 100644 --- a/lib/src/common/CMakeLists.txt +++ b/lib/src/common/CMakeLists.txt @@ -27,7 +27,6 @@ set(SOURCES arch_select.cc liblte_security.cc log_filter.cc logmap.cc - logger_file.cc logger_srslog_wrapper.cc mac_pcap.cc nas_pcap.cc @@ -58,6 +57,6 @@ add_dependencies(srslte_common gen_build_info) add_executable(arch_select arch_select.cc) target_include_directories(srslte_common PUBLIC ${SEC_INCLUDE_DIRS}) -target_link_libraries(srslte_common srslte_phy ${SEC_LIBRARIES}) +target_link_libraries(srslte_common srslte_phy srslog ${SEC_LIBRARIES}) add_subdirectory(test) diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index 20c5d29f4..102817ffe 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -28,6 +28,7 @@ #include #include "srslte/common/log_filter.h" +#include "srslte/srslog/srslog.h" namespace srslte { @@ -42,12 +43,30 @@ log_filter::log_filter() : log() logger_h = NULL; } +/// Creates a log channel that writes to stdout. +static srslog::log_channel* create_or_get_default_logger() +{ + srslog::sink* s = srslog::create_stdout_sink(); + if (!s) { + s = srslog::find_sink("stdout"); + } + srslog::log_channel* log = srslog::create_log_channel("log_filter_default", *s); + if (!log) { + log = srslog::find_log_channel("log_filter_default"); + } + + srslog::init(); + + return log; +} + log_filter::log_filter(std::string layer) : log() { - do_tti = false; - time_src = NULL; - time_format = TIME; - init(layer, &def_logger_stdout, do_tti); + do_tti = false; + time_src = NULL; + time_format = TIME; + default_logger = std::unique_ptr(new srslog_wrapper(*create_or_get_default_logger())); + init(layer, default_logger.get(), do_tti); } log_filter::log_filter(std::string layer, logger* logger_, bool tti) : log() @@ -57,7 +76,8 @@ log_filter::log_filter(std::string layer, logger* logger_, bool tti) : log() time_format = TIME; if (!logger_) { - logger_ = &def_logger_stdout; + default_logger = std::unique_ptr(new srslog_wrapper(*create_or_get_default_logger())); + logger_ = default_logger.get(); } init(std::move(layer), logger_, tti); diff --git a/lib/src/common/logger_file.cc b/lib/src/common/logger_file.cc deleted file mode 100644 index b9fa4d0cd..000000000 --- a/lib/src/common/logger_file.cc +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2013-2020 Software Radio Systems Limited - * - * This file is part of srsLTE. - * - * srsLTE is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * srsLTE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * A copy of the GNU Affero General Public License can be found in - * the LICENSE file in the top-level directory of this distribution - * and at http://www.gnu.org/licenses/. - * - */ - -#define LOG_BUFFER_SIZE 1024 * 32 - -#include "srslte/common/logger_file.h" - -using namespace std; - -namespace srslte { - -logger_file::logger_file() : logfile(NULL), is_running(false), cur_length(0), max_length(0), thread("LOGGER_FILE") -{ - pthread_mutex_init(&mutex, NULL); - pthread_cond_init(¬_empty, NULL); -} - -logger_file::~logger_file() -{ - stop(); - pthread_mutex_destroy(&mutex); - pthread_cond_destroy(¬_empty); -} - -void logger_file::init(std::string file, int max_length_) -{ - if (is_running) { - fprintf(stderr, "Error: logger thread is already running.\n"); - return; - } - pthread_mutex_lock(&mutex); - max_length = (int64_t)max_length_ * 1024; - name_idx = 0; - filename = file; - logfile = fopen(filename.c_str(), "w"); - if (logfile == NULL) { - printf("Error: could not create log file, no messages will be logged!\n"); - } - is_running = true; - start(-2); - pthread_mutex_unlock(&mutex); -} - -void logger_file::stop() -{ - if (is_running) { - logger::log_char("Closing log\n"); - pthread_mutex_lock(&mutex); - is_running = false; - pthread_cond_signal(¬_empty); // wakeup thread and let it terminate - pthread_mutex_unlock(&mutex); - wait_thread_finish(); - pthread_mutex_lock(&mutex); - flush(); - if (logfile) { - fclose(logfile); - logfile = NULL; - } - pthread_mutex_unlock(&mutex); - } else { - pthread_mutex_lock(&mutex); - flush(); // flush even if thread isn't running anymore - pthread_mutex_unlock(&mutex); - } -} - -void logger_file::log(unique_log_str_t msg) -{ - pthread_mutex_lock(&mutex); - buffer.push_back(std::move(msg)); - pthread_cond_signal(¬_empty); - pthread_mutex_unlock(&mutex); -} - -void logger_file::run_thread() -{ - while (is_running) { - pthread_mutex_lock(&mutex); - while (buffer.empty()) { - pthread_cond_wait(¬_empty, &mutex); - if (!is_running) { - pthread_mutex_unlock(&mutex); - return; // Thread done. Messages in buffer will be handled in flush. - } - } - unique_log_str_t s = std::move(buffer.front()); - - int n = 0; - if (logfile) { - n = fprintf(logfile, "%s", s->str()); - } - buffer.pop_front(); - - if (n > 0) { - cur_length += (int64_t)n; - if (cur_length >= max_length && max_length > 0) { - fclose(logfile); - name_idx++; - char numstr[21]; // enough to hold all numbers up to 64-bits - sprintf(numstr, ".%d", name_idx); - string newfilename = filename + numstr; - logfile = fopen(newfilename.c_str(), "w"); - if (logfile == NULL) { - printf("Error: could not create log file, no messages will be logged!\n"); - } - cur_length = 0; - } - } - pthread_mutex_unlock(&mutex); - } -} - -void logger_file::flush() -{ - std::deque::iterator it; - for (it = buffer.begin(); it != buffer.end(); it++) { - unique_log_str_t s = std::move(*it); - if (logfile) { - fprintf(logfile, "%s", s->str()); - } - } - buffer.clear(); -} - -} // namespace srslte diff --git a/lib/src/common/logmap.cc b/lib/src/common/logmap.cc index 617ff67f7..10c145bc9 100644 --- a/lib/src/common/logmap.cc +++ b/lib/src/common/logmap.cc @@ -21,7 +21,7 @@ #include "srslte/common/logmap.h" #include "srslte/common/log_filter.h" -#include "srslte/common/logger_stdout.h" +#include "srslte/srslog/srslog.h" using namespace srslte; @@ -30,9 +30,27 @@ log_ref::log_ref(const char* name) ptr_ = srslte::logmap::get(name).ptr_; } -logmap::logmap() : logger_stdout_val(new logger_stdout{}) +/// Creates a log channel that writes to stdout. +static srslog::log_channel* create_or_get_default_logger() { - default_logger = logger_stdout_val.get(); + srslog::sink* s = srslog::create_stdout_sink(); + if (!s) { + s = srslog::find_sink("stdout"); + } + srslog::log_channel* log = srslog::create_log_channel("logmap_default", *s); + if (!log) { + log = srslog::find_log_channel("logmap_default"); + } + + srslog::init(); + + return log; +} + +logmap::logmap() +{ + stdout_channel = std::unique_ptr(new srslog_wrapper(*create_or_get_default_logger())); + default_logger = stdout_channel.get(); } // Access to log map by servicename. If servicename does not exist, create a new log_filter with default cfg diff --git a/lib/src/common/test/thread_pool_test.cc b/lib/src/common/test/thread_pool_test.cc index a4fad8e13..803565d14 100644 --- a/lib/src/common/test/thread_pool_test.cc +++ b/lib/src/common/test/thread_pool_test.cc @@ -19,9 +19,11 @@ * */ #include +#include #include #include #include +#include class dummy_radio { @@ -128,8 +130,21 @@ 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); + + // Start the log backend. + srslog::init(); + // Loggers - srslte::logger_stdout logger; srslte::log_filter radio_log("radio", &logger); std::vector > worker_logs; diff --git a/lib/test/common/CMakeLists.txt b/lib/test/common/CMakeLists.txt index 1d270bd4d..688b32feb 100644 --- a/lib/test/common/CMakeLists.txt +++ b/lib/test/common/CMakeLists.txt @@ -23,10 +23,6 @@ find_package(SCTP REQUIRED) ####################################################################### # COMMON TESTS ####################################################################### -add_executable(logger_file_test logger_file_test.cc) -target_link_libraries(logger_file_test srslte_phy srslte_common srslte_phy ${SEC_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -add_test(logger_file_test logger_file_test) - add_executable(byte_buffer_queue_test byte_buffer_queue_test.cc) target_link_libraries(byte_buffer_queue_test srslte_phy srslte_common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) add_test(byte_buffer_queue_test byte_buffer_queue_test) diff --git a/lib/test/common/log_filter_test.cc b/lib/test/common/log_filter_test.cc index 27ac75672..e4ba60ee7 100644 --- a/lib/test/common/log_filter_test.cc +++ b/lib/test/common/log_filter_test.cc @@ -23,16 +23,17 @@ #define NMSGS 100 #include "srslte/common/log_filter.h" -#include "srslte/common/logger_file.h" +#include "srslte/common/logger_srslog_wrapper.h" #include "srslte/common/logmap.h" #include "srslte/common/test_common.h" +#include "srslte/srslog/srslog.h" #include using namespace srslte; typedef struct { - logger_file* l; - int thread_id; + logger* l; + int thread_id; } args_t; void* thread_loop(void* a) @@ -78,8 +79,10 @@ void* thread_loop_hex(void* a) void write(std::string filename) { - logger_file l; - l.init(filename); + srslog::sink* s = srslog::create_file_sink(filename); + srslog::log_channel* chan = srslog::create_log_channel("write", *s); + srslte::srslog_wrapper l(*chan); + pthread_t threads[NTHREADS]; args_t args[NTHREADS]; for (int i = 0; i < NTHREADS; i++) { @@ -121,7 +124,15 @@ bool read(std::string filename) int basic_hex_test() { - logger_stdout l; + srslog::sink* s = srslog::find_sink("stdout"); + if (!s) { + return SRSLTE_ERROR; + } + srslog::log_channel* chan = srslog::create_log_channel("basic_hex_test", *s); + if (!chan) { + return SRSLTE_ERROR; + } + srslte::srslog_wrapper l(*chan); log_filter filter("layer", &l); filter.set_level(LOG_LEVEL_DEBUG); @@ -183,11 +194,10 @@ int test_log_ref() int full_test() { - bool result; std::string f("log.txt"); write(f); #if 0 - result = read(f); + bool result = read(f); remove(f.c_str()); if(result) { printf("Passed\n"); @@ -203,6 +213,12 @@ int full_test() int main(int argc, char** argv) { + // Setup logging. + srslog::sink* log_sink = srslog::create_stdout_sink(); + if (!log_sink) { + return SRSLTE_ERROR; + } + TESTASSERT(basic_hex_test() == SRSLTE_SUCCESS); TESTASSERT(full_test() == SRSLTE_SUCCESS); TESTASSERT(test_log_singleton() == SRSLTE_SUCCESS); diff --git a/lib/test/common/logger_file_test.cc b/lib/test/common/logger_file_test.cc deleted file mode 100644 index 5d40a664c..000000000 --- a/lib/test/common/logger_file_test.cc +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2013-2020 Software Radio Systems Limited - * - * This file is part of srsLTE. - * - * srsLTE is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * srsLTE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * A copy of the GNU Affero General Public License can be found in - * the LICENSE file in the top-level directory of this distribution - * and at http://www.gnu.org/licenses/. - * - */ - -#define NTHREADS 100 -#define NMSGS 100 - -#include "srslte/common/logger_file.h" -#include -#include - -using namespace srslte; - -typedef struct { - logger_file* l; - int thread_id; -} args_t; - -void* thread_loop(void* a) -{ - args_t* args = (args_t*)a; - char buf[100]; - for (int i = 0; i < NMSGS; i++) { - sprintf(buf, "Thread %d: %d", args->thread_id, i); - args->l->log_char(buf); - } - return NULL; -} - -void write(std::string filename) -{ - logger_file l; - l.init(filename); - pthread_t threads[NTHREADS]; - args_t args[NTHREADS]; - for (int i = 0; i < NTHREADS; i++) { - args[i].l = &l; - args[i].thread_id = i; - pthread_create(&threads[i], NULL, &thread_loop, &args[i]); - } - for (int i = 0; i < NTHREADS; i++) { - pthread_join(threads[i], NULL); - } -} - -bool read(std::string filename) -{ - bool pass = true; - bool written[NTHREADS][NMSGS]; - int thread = 0, msg = 0; - int r; - - for (int i = 0; i < NTHREADS; i++) { - for (int j = 0; j < NMSGS; j++) { - written[i][j] = false; - } - } - FILE* f = fopen(filename.c_str(), "r"); - if (f != NULL) { - while (fscanf(f, "Thread %d: %d\n", &thread, &msg)) { - if (thread < NTHREADS && msg < NMSGS) { - written[thread][msg] = true; - } else { - perror("Wrong thread and/or msg"); - fclose(f); - return false; - } - } - fclose(f); - } - for (int i = 0; i < NTHREADS; i++) { - for (int j = 0; j < NMSGS; j++) { - if (!written[i][j]) - pass = false; - } - } - return pass; -} - -int main(int argc, char** argv) -{ - bool result; - std::string f("log.txt"); - write(f); - result = read(f); - - if (remove(f.c_str())) { - perror("Removing file"); - } - - if (result) { - printf("Passed\n"); - exit(0); - } else { - printf("Failed\n;"); - exit(1); - } -} diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index a7fa2f3aa..6bfee037f 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -20,7 +20,6 @@ */ #include "srslte/common/log_filter.h" -#include "srslte/common/logger_stdout.h" #include "srslte/common/rlc_pcap.h" #include "srslte/common/test_common.h" #include "srslte/common/threads.h" diff --git a/lib/test/upper/rlc_stress_test.cc b/lib/test/upper/rlc_stress_test.cc index ba4fef745..358d842a6 100644 --- a/lib/test/upper/rlc_stress_test.cc +++ b/lib/test/upper/rlc_stress_test.cc @@ -21,7 +21,6 @@ #include "srslte/common/crash_handler.h" #include "srslte/common/log_filter.h" -#include "srslte/common/logger_stdout.h" #include "srslte/common/rlc_pcap.h" #include "srslte/common/threads.h" #include "srslte/upper/rlc.h" diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index c2a9ab4ab..49b7e2ae6 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -45,7 +45,6 @@ #include "srslte/common/buffer_pool.h" #include "srslte/common/interfaces_common.h" #include "srslte/common/log_filter.h" -#include "srslte/common/logger_file.h" #include "srslte/common/mac_pcap.h" #include "srslte/common/security.h" #include "srslte/interfaces/enb_metrics_interface.h" @@ -144,8 +143,6 @@ private: std::unique_ptr radio = nullptr; std::unique_ptr phy = nullptr; - srslte::logger_stdout logger_stdout; - srslte::logger_file logger_file; srslte::logger* logger = nullptr; srslte::log_ref log; // Own logger for eNB diff --git a/srsenb/src/CMakeLists.txt b/srsenb/src/CMakeLists.txt index f340b3091..4527308fa 100644 --- a/srsenb/src/CMakeLists.txt +++ b/srsenb/src/CMakeLists.txt @@ -36,8 +36,8 @@ add_library(enb_cfg_parser parser.cc enb_cfg_parser.cc) add_executable(srsenb main.cc enb.cc metrics_stdout.cc metrics_csv.cc) -set(SRSENB_SOURCES srsenb_phy srsenb_stack srsenb_upper srsenb_mac srsenb_rrc) -set(SRSLTE_SOURCES srslte_common srslte_mac srslte_phy srslte_upper srslte_radio rrc_asn1 s1ap_asn1 enb_cfg_parser) +set(SRSENB_SOURCES srsenb_phy srsenb_stack srsenb_upper srsenb_mac srsenb_rrc srslog) +set(SRSLTE_SOURCES srslte_common srslte_mac srslte_phy srslte_upper srslte_radio rrc_asn1 s1ap_asn1 enb_cfg_parser srslog) if(ENABLE_5GNR) set(SRSENB_SOURCES ${SRSENB_SOURCES} srsgnb_phy srsgnb_stack srsgnb_upper srsgnb_mac srsgnb_rrc) diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index 27459b910..17ffd8223 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -28,7 +28,9 @@ #include "srslte/common/common_helper.h" #include "srslte/common/config_file.h" #include "srslte/common/crash_handler.h" +#include "srslte/common/logger_srslog_wrapper.h" #include "srslte/common/signal_handler.h" +#include "srslte/srslog/srslog.h" #include #include @@ -127,7 +129,7 @@ void parse_args(all_args_t* args, int argc, char* argv[]) ("pcap.filename", bpo::value(&args->stack.mac_pcap.filename)->default_value("enb_mac.pcap"), "MAC layer capture filename") ("pcap.s1ap_enable", bpo::value(&args->stack.s1ap_pcap.enable)->default_value(false), "Enable S1AP packet captures for wireshark") ("pcap.s1ap_filename", bpo::value(&args->stack.s1ap_pcap.filename)->default_value("enb_s1ap.pcap"), "S1AP layer capture filename") - + /* MCS section */ ("scheduler.pdsch_mcs", bpo::value(&args->stack.mac.sched.pdsch_mcs)->default_value(-1), "Optional fixed PDSCH MCS (ignores reported CQIs if specified)") ("scheduler.pdsch_max_mcs", bpo::value(&args->stack.mac.sched.pdsch_max_mcs)->default_value(-1), "Optional PDSCH MCS limit") @@ -201,7 +203,7 @@ void parse_args(all_args_t* args, int argc, char* argv[]) // NR section ("scheduler.tb_len", bpo::value(&args->stack.mac.nr_tb_size)->default_value(1520), "Default TB size") - + // VNF params ("vnf.type", bpo::value(&args->phy.vnf_args.type)->default_value("gnb"), "VNF instance type [gnb,ue]") ("vnf.addr", bpo::value(&args->phy.vnf_args.bind_addr)->default_value("localhost"), "Address to bind VNF interface") @@ -416,6 +418,12 @@ void* input_loop(void* m) return nullptr; } +/// Adjusts the input value in args from kbytes to bytes. +static size_t fixup_log_file_maxsize(int x) +{ + return (x < 0) ? 0 : size_t(x) * 1024u; +} + int main(int argc, char* argv[]) { srslte_register_signal_handler(); @@ -428,23 +436,30 @@ int main(int argc, char* argv[]) srslte_debug_handle_crash(argc, argv); parse_args(&args, argc, argv); - srslte::logger_stdout logger_stdout; + // Setup logging. + log_sink = (args.log.filename == "stdout") + ? srslog::create_stdout_sink() + : srslog::create_file_sink(args.log.filename, fixup_log_file_maxsize(args.log.file_max_size)); + if (!log_sink) { + return SRSLTE_ERROR; + } - // Set logger - srslte::logger* logger = nullptr; - if (args.log.filename == "stdout") { - logger = &logger_stdout; - } else { - logger_file.init(args.log.filename, args.log.file_max_size); - logger = &logger_file; + srslog::log_channel* chan = srslog::create_log_channel("main_channel", *log_sink); + if (!chan) { + return SRSLTE_ERROR; } - srslte::logmap::set_default_logger(logger); + srslte::srslog_wrapper log_wrapper(*chan); + + // Start the log backend. + srslog::init(); + + srslte::logmap::set_default_logger(&log_wrapper); srslte::logmap::get("COMMON")->set_level(srslte::LOG_LEVEL_INFO); log_args(argc, argv, "ENB"); // Create eNB unique_ptr enb{new srsenb::enb}; - if (enb->init(args, logger) != SRSLTE_SUCCESS) { + if (enb->init(args, &log_wrapper) != SRSLTE_SUCCESS) { enb->stop(); return SRSLTE_ERROR; } diff --git a/srsenb/test/phy/CMakeLists.txt b/srsenb/test/phy/CMakeLists.txt index 993a72729..c315b4cf2 100644 --- a/srsenb/test/phy/CMakeLists.txt +++ b/srsenb/test/phy/CMakeLists.txt @@ -47,7 +47,7 @@ set_tests_properties(enb_phy_test_tm1 PROPERTIES LABELS "long;phy;srsenb") # - Single carrier # - Transmission Mode 2 # - 1 eNb cell/carrier (no carrier aggregation) -# - 6 PRB +# - 100 PRB add_test(enb_phy_test_tm2 enb_phy_test --duration=${ENB_PHY_TEST_DURATION} --cell.nof_prb=100 --tm=2) set_tests_properties(enb_phy_test_tm2 PROPERTIES LABELS "long;phy;srsenb") @@ -55,7 +55,7 @@ set_tests_properties(enb_phy_test_tm2 PROPERTIES LABELS "long;phy;srsenb") # - Single carrier # - Transmission Mode 3 # - 1 eNb cell/carrier (no carrier aggregation) -# - 6 PRB +# - 100 PRB add_test(enb_phy_test_tm3 enb_phy_test --duration=${ENB_PHY_TEST_DURATION} --cell.nof_prb=100 --tm=3) set_tests_properties(enb_phy_test_tm3 PROPERTIES LABELS "long;phy;srsenb") @@ -63,7 +63,7 @@ set_tests_properties(enb_phy_test_tm3 PROPERTIES LABELS "long;phy;srsenb") # - Single carrier # - Transmission Mode 4 # - 1 eNb cell/carrier (no carrier aggregation) -# - 6 PRB +# - 100 PRB add_test(enb_phy_test_tm4 enb_phy_test --duration=${ENB_PHY_TEST_DURATION} --cell.nof_prb=100 --tm=4) set_tests_properties(enb_phy_test_tm4 PROPERTIES LABELS "long;phy;srsenb") diff --git a/srsenb/test/phy/enb_phy_test.cc b/srsenb/test/phy/enb_phy_test.cc index d27181c5e..4b1788056 100644 --- a/srsenb/test/phy/enb_phy_test.cc +++ b/srsenb/test/phy/enb_phy_test.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include static inline bool dl_ack_value(uint32_t ue_cc_idx, uint32_t tti) @@ -1176,7 +1178,6 @@ private: unique_srsenb_phy_t enb_phy; unique_dummy_ue_phy_t ue_phy; srslte::log_filter log_h; - srslte::logger_stdout logger_stdout; args_t args = {}; ///< Test arguments srsenb::phy_args_t phy_args; ///< PHY arguments @@ -1192,7 +1193,7 @@ private: change_state_t change_state = change_state_assert; public: - explicit phy_test_bench(args_t& args_) : log_h("TEST BENCH") + phy_test_bench(args_t& args_, srslte::logger& logger_) : log_h("TEST BENCH") { // Copy test arguments args = args_; @@ -1290,7 +1291,7 @@ public: stack->set_active_cell_list(args.ue_cell_list); /// eNb PHY initialisation instance - enb_phy = unique_srsenb_phy_t(new srsenb::phy(&logger_stdout)); + enb_phy = unique_srsenb_phy_t(new srsenb::phy(&logger_)); /// Initiate eNb PHY with the given RNTI enb_phy->init(phy_args, phy_cfg, radio.get(), stack.get()); @@ -1446,8 +1447,20 @@ int main(int argc, char** argv) // Initialize secondary parameters test_args.init(); + // Setup logging. + srslog::sink* log_sink = srslog::create_stdout_sink(); + if (!log_sink) { + return SRSLTE_ERROR; + } + + srslog::log_channel* chan = srslog::create_log_channel("main_channel", *log_sink); + if (!chan) { + return SRSLTE_ERROR; + } + srslte::srslog_wrapper log_wrapper(*chan); + // Create Test Bench - unique_phy_test_bench test_bench = unique_phy_test_bench(new phy_test_bench(test_args)); + unique_phy_test_bench test_bench = unique_phy_test_bench(new phy_test_bench(test_args, log_wrapper)); // Run Simulation for (uint32_t i = 0; i < test_args.duration; i++) { diff --git a/srsenb/test/rrc/rrc_nr_test.cc b/srsenb/test/rrc/rrc_nr_test.cc index e4c818995..9c7d42645 100644 --- a/srsenb/test/rrc/rrc_nr_test.cc +++ b/srsenb/test/rrc/rrc_nr_test.cc @@ -44,7 +44,6 @@ int test_cell_cfg(const srsenb::sched_interface::cell_cfg_t& cellcfg) */ int test_sib_generation() { - srslte::logger_stdout logger; srslte::timer_handler timers_db(128); mac_dummy mac_obj; @@ -73,7 +72,6 @@ int test_sib_generation() int test_rrc_setup() { - srslte::logger_stdout logger; srslte::timer_handler timers_db(128); mac_dummy mac_obj; @@ -104,4 +102,4 @@ int main() TESTASSERT(srsenb::test_rrc_setup() == SRSLTE_SUCCESS); return 0; -} \ No newline at end of file +} diff --git a/srsepc/hdr/hss/hss.h b/srsepc/hdr/hss/hss.h index 76dc99db0..c916bdf72 100644 --- a/srsepc/hdr/hss/hss.h +++ b/srsepc/hdr/hss/hss.h @@ -31,7 +31,6 @@ #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" #include "srslte/common/log_filter.h" -#include "srslte/common/logger_file.h" #include "srslte/interfaces/epc_interfaces.h" #include #include diff --git a/srsepc/hdr/mbms-gw/mbms-gw.h b/srsepc/hdr/mbms-gw/mbms-gw.h index c91f9db1c..50e41fc60 100644 --- a/srsepc/hdr/mbms-gw/mbms-gw.h +++ b/srsepc/hdr/mbms-gw/mbms-gw.h @@ -31,7 +31,6 @@ #include "srslte/asn1/gtpc.h" #include "srslte/common/buffer_pool.h" #include "srslte/common/log_filter.h" -#include "srslte/common/logger_file.h" #include "srslte/common/logmap.h" #include "srslte/common/threads.h" #include "srslte/srslte.h" diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index be92739ef..b443e61ec 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -32,7 +32,6 @@ #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" #include "srslte/common/log_filter.h" -#include "srslte/common/logger_file.h" #include "srslte/common/threads.h" #include diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 9f69b7257..a048b4a56 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -31,7 +31,6 @@ #include "srslte/asn1/gtpc.h" #include "srslte/common/buffer_pool.h" #include "srslte/common/log_filter.h" -#include "srslte/common/logger_file.h" #include "srslte/common/logmap.h" #include "srslte/common/threads.h" #include diff --git a/srsepc/src/CMakeLists.txt b/srsepc/src/CMakeLists.txt index afcbcbbcb..75f3cd851 100644 --- a/srsepc/src/CMakeLists.txt +++ b/srsepc/src/CMakeLists.txt @@ -41,6 +41,7 @@ target_link_libraries( srsepc srsepc_mme s1ap_asn1 srslte_upper srslte_common + srslog ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${SEC_LIBRARIES} @@ -51,8 +52,9 @@ add_executable(srsmbms mbms-gw/main.cc ) target_link_libraries(srsmbms srsepc_mbms_gw srslte_upper srslte_common - ${CMAKE_THREAD_LIBS_INIT} - ${Boost_LIBRARIES} + srslog + ${CMAKE_THREAD_LIBS_INIT} + ${Boost_LIBRARIES} ${SEC_LIBRARIES} ${LIBCONFIGPP_LIBRARIES} ${SCTP_LIBRARIES}) diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index e393301e8..3e713d95a 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -27,7 +27,9 @@ #include "srslte/common/common_helper.h" #include "srslte/common/config_file.h" #include "srslte/common/crash_handler.h" +#include "srslte/common/logger_srslog_wrapper.h" #include "srslte/common/signal_handler.h" +#include "srslte/srslog/srslog.h" #include #include #include @@ -386,44 +388,52 @@ int main(int argc, char* argv[]) all_args_t args; parse_args(&args, argc, argv); - srslte::logger_stdout logger_stdout; - srslte::logger* logger; + // Setup logging. + log_sink = (args.log_args.filename == "stdout") ? srslog::create_stdout_sink() + : srslog::create_file_sink(args.log_args.filename); + if (!log_sink) { + return SRSLTE_ERROR; + } + srslog::log_channel* chan = srslog::create_log_channel("main_channel", *log_sink); + if (!chan) { + return SRSLTE_ERROR; + } + srslte::srslog_wrapper log_wrapper(*chan); - /*Init logger*/ - if (args.log_args.filename == "stdout") { - logger = &logger_stdout; - } else { - logger_file.init(args.log_args.filename); - logger_file.log_char("\n\n"); - logger_file.log_char(get_build_string().c_str()); - logger_file.log_char("\n--- Software Radio Systems EPC log ---\n\n"); - logger = &logger_file; + // Start the log backend. + srslog::init(); + + if (args.log_args.filename != "stdout") { + log_wrapper.log_char("\n\n"); + log_wrapper.log_char(get_build_string().c_str()); + log_wrapper.log_char("\n--- Software Radio Systems EPC log ---\n\n"); } - srslte::logmap::set_default_logger(logger); + + srslte::logmap::set_default_logger(&log_wrapper); log_args(argc, argv, "EPC"); srslte::log_filter nas_log; - nas_log.init("NAS ", logger); + nas_log.init("NAS ", &log_wrapper); nas_log.set_level(level(args.log_args.nas_level)); nas_log.set_hex_limit(args.log_args.nas_hex_limit); srslte::log_filter s1ap_log; - s1ap_log.init("S1AP", logger); + s1ap_log.init("S1AP", &log_wrapper); s1ap_log.set_level(level(args.log_args.s1ap_level)); s1ap_log.set_hex_limit(args.log_args.s1ap_hex_limit); srslte::log_filter mme_gtpc_log; - mme_gtpc_log.init("MME GTPC", logger); + mme_gtpc_log.init("MME GTPC", &log_wrapper); mme_gtpc_log.set_level(level(args.log_args.mme_gtpc_level)); mme_gtpc_log.set_hex_limit(args.log_args.mme_gtpc_hex_limit); srslte::log_filter hss_log; - hss_log.init("HSS ", logger); + hss_log.init("HSS ", &log_wrapper); hss_log.set_level(level(args.log_args.hss_level)); hss_log.set_hex_limit(args.log_args.hss_hex_limit); srslte::log_filter spgw_gtpc_log; - spgw_gtpc_log.init("SPGW GTPC", logger); + spgw_gtpc_log.init("SPGW GTPC", &log_wrapper); spgw_gtpc_log.set_level(level(args.log_args.spgw_gtpc_level)); spgw_gtpc_log.set_hex_limit(args.log_args.spgw_gtpc_hex_limit); @@ -432,7 +442,7 @@ int main(int argc, char* argv[]) gtpu_log->set_hex_limit(args.log_args.mme_gtpc_hex_limit); srslte::log_filter spgw_log; - spgw_log.init("SPGW", logger); + spgw_log.init("SPGW", &log_wrapper); spgw_log.set_level(level(args.log_args.spgw_level)); spgw_log.set_hex_limit(args.log_args.spgw_hex_limit); diff --git a/srsepc/src/mbms-gw/main.cc b/srsepc/src/mbms-gw/main.cc index 5b40e2fcb..8c424f442 100644 --- a/srsepc/src/mbms-gw/main.cc +++ b/srsepc/src/mbms-gw/main.cc @@ -18,8 +18,11 @@ * and at http://www.gnu.org/licenses/. * */ + #include "srsepc/hdr/mbms-gw/mbms-gw.h" #include "srslte/common/config_file.h" +#include "srslte/common/logger_srslog_wrapper.h" +#include "srslte/srslog/srslog.h" #include #include #include @@ -192,19 +195,25 @@ int main(int argc, char* argv[]) all_args_t args; parse_args(&args, argc, argv); - srslte::logger_stdout logger_stdout; - srslte::logger_file logger_file; - srslte::logger* logger; + srslog::sink* log_sink = (args.log_args.filename == "stdout") ? srslog::create_stdout_sink() + : srslog::create_file_sink(args.log_args.filename); + if (!log_sink) { + return SRSLTE_ERROR; + } + srslog::log_channel* chan = srslog::create_log_channel("main_channel", *log_sink); + if (!chan) { + return SRSLTE_ERROR; + } + srslte::srslog_wrapper log_wrapper(*chan); + + // Start the log backend. + srslog::init(); - /*Init logger*/ - if (!args.log_args.filename.compare("stdout")) { - logger = &logger_stdout; - } else { - logger_file.init(args.log_args.filename); - logger_file.log_char("\n--- Software Radio Systems MBMS log ---\n\n"); - logger = &logger_file; + if (args.log_args.filename != "stdout") { + log_wrapper.log_char("\n--- Software Radio Systems MBMS log ---\n\n"); } - srslte::logmap::set_default_logger(logger); + + srslte::logmap::set_default_logger(&log_wrapper); srslte::log_ref mbms_gw_log{"MBMS"}; mbms_gw_log->set_level(level(args.log_args.mbms_gw_level)); diff --git a/srsepc/src/mme/nas.cc b/srsepc/src/mme/nas.cc index a9bff4d90..7f96ea918 100644 --- a/srsepc/src/mme/nas.cc +++ b/srsepc/src/mme/nas.cc @@ -25,6 +25,7 @@ #include "srslte/common/security.h" #include #include // for printing uint64_t +#include namespace srsepc { diff --git a/srsue/hdr/ue.h b/srsue/hdr/ue.h index 06482d7d6..78f2a7347 100644 --- a/srsue/hdr/ue.h +++ b/srsue/hdr/ue.h @@ -35,7 +35,6 @@ #include "phy/ue_phy_base.h" #include "srslte/common/buffer_pool.h" #include "srslte/common/log_filter.h" -#include "srslte/common/logger_file.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/radio/radio.h" #include "stack/ue_stack_base.h" diff --git a/srsue/test/phy/ue_phy_test.cc b/srsue/test/phy/ue_phy_test.cc index 5e1d33fd2..00090e93c 100644 --- a/srsue/test/phy/ue_phy_test.cc +++ b/srsue/test/phy/ue_phy_test.cc @@ -18,9 +18,12 @@ * and at http://www.gnu.org/licenses/. * */ + +#include #include #include #include +#include #include #include @@ -320,8 +323,7 @@ private: }; // Common instances - srslte::logger_stdout main_logger; - srslte::log_filter log_h; + srslte::log_filter log_h; // Dummy instances dummy_stack stack; @@ -343,9 +345,9 @@ private: std::condition_variable cvar; public: - phy_test_bench(const srsue::phy_args_t& phy_args, const srslte_cell_t& cell) : - stack(main_logger), - radio(main_logger, cell.nof_ports, srslte_sampling_freq_hz(cell.nof_prb)), + phy_test_bench(const srsue::phy_args_t& phy_args, const srslte_cell_t& cell, srslte::logger& logger_) : + stack(logger_), + radio(logger_, cell.nof_ports, srslte_sampling_freq_hz(cell.nof_prb)), thread("phy_test_bench"), log_h("test bench") { @@ -353,7 +355,7 @@ public: sf_len = SRSLTE_SF_LEN_PRB(cell.nof_prb); // Initialise UE - phy = std::unique_ptr(new srsue::phy(&main_logger)); + phy = std::unique_ptr(new srsue::phy(&logger_)); phy->init(phy_args, &stack, &radio); // Initialise DL baseband buffers @@ -481,8 +483,23 @@ int main(int argc, char** argv) // Set custom test cell and arguments here phy_args.log.phy_level = "info"; + // Setup logging. + srslog::sink* log_sink = srslog::create_stdout_sink(); + if (!log_sink) { + return SRSLTE_ERROR; + } + srslog::log_channel* chan = srslog::create_log_channel("main_channel", *log_sink); + if (!chan) { + return SRSLTE_ERROR; + } + srslte::srslog_wrapper log_wrapper(*chan); + + // Start the log backend. + srslog::init(); + // Create test bench - std::unique_ptr phy_test = std::unique_ptr(new phy_test_bench(phy_args, cell)); + std::unique_ptr phy_test = + std::unique_ptr(new phy_test_bench(phy_args, cell, log_wrapper)); phy_test->set_loglevel("info"); // Start test bench diff --git a/srsue/test/ttcn3/hdr/ttcn3_syssim.h b/srsue/test/ttcn3/hdr/ttcn3_syssim.h index 4797c915e..218845975 100644 --- a/srsue/test/ttcn3/hdr/ttcn3_syssim.h +++ b/srsue/test/ttcn3/hdr/ttcn3_syssim.h @@ -49,7 +49,7 @@ class ttcn3_syssim : public syssim_interface_phy, public srslte::pdu_queue::process_callback { public: - ttcn3_syssim(srslte::logger_file* logger_file_, ttcn3_ue* ue_); + ttcn3_syssim(srslte::logger& logger_file_, srslte::logger& logger_stdout_, ttcn3_ue* ue_); ~ttcn3_syssim(); @@ -225,19 +225,20 @@ private: epoll_signal_handler signal_handler; // Logging stuff - srslte::logger_stdout logger_stdout; - srslte::logger_file* logger_file = nullptr; - srslte::logger* logger = nullptr; - srslte::log_ref log; - srslte::log_filter ut_log; - srslte::log_filter sys_log; - srslte::log_filter ip_sock_log; - srslte::log_filter ip_ctrl_log; - srslte::log_filter srb_log; - srslte::log_filter drb_log; - srslte::log_ref ss_mac_log{"SS-MAC"}; - srslte::log_ref ss_rlc_log{"SS-RLC"}; - srslte::log_ref ss_pdcp_log{"SS-PDCP"}; + srslte::logger& logger_stdout; + srslte::logger& logger_file; + std::unique_ptr test_case_logger; + srslte::logger* logger_ptr = nullptr; + srslte::log_ref log; + srslte::log_filter ut_log; + srslte::log_filter sys_log; + srslte::log_filter ip_sock_log; + srslte::log_filter ip_ctrl_log; + srslte::log_filter srb_log; + srslte::log_filter drb_log; + srslte::log_ref ss_mac_log{"SS-MAC"}; + srslte::log_ref ss_rlc_log{"SS-RLC"}; + srslte::log_ref ss_pdcp_log{"SS-PDCP"}; all_args_t args = {}; diff --git a/srsue/test/ttcn3/src/ttcn3_dut.cc b/srsue/test/ttcn3/src/ttcn3_dut.cc index 912bdbaa6..65c5cf0b4 100644 --- a/srsue/test/ttcn3/src/ttcn3_dut.cc +++ b/srsue/test/ttcn3/src/ttcn3_dut.cc @@ -20,7 +20,9 @@ */ #include "srslte/build_info.h" +#include "srslte/common/logger_srslog_wrapper.h" #include "srslte/common/logmap.h" +#include "srslte/srslog/srslog.h" #include "srsue/hdr/ue.h" #include "ttcn3_syssim.h" #include @@ -116,17 +118,39 @@ int main(int argc, char** argv) std::cout << "Built in " << srslte_get_build_mode() << " mode using " << srslte_get_build_info() << "." << std::endl; ttcn3_dut_args_t dut_args = {}; - all_args_t ue_args = parse_args(&dut_args, argc, argv); + all_args_t ue_args = parse_args(&dut_args, argc, argv); + + // Setup logging. + srslog::sink* log_file_sink = srslog::create_file_sink(dut_args.log_filename); + if (!log_file_sink) { + return SRSLTE_ERROR; + } + srslog::log_channel* file_chan = srslog::create_log_channel("file_channel", *log_file_sink); + if (!file_chan) { + return SRSLTE_ERROR; + } + srslog::sink* stdout_sink = srslog::create_stdout_sink(); + if (!stdout_sink) { + return SRSLTE_ERROR; + } + srslog::log_channel* stdout_chan = srslog::create_log_channel("stdout_channel", *stdout_sink); + if (!stdout_chan) { + return SRSLTE_ERROR; + } + srslte::srslog_wrapper stdout_wrapper(*stdout_chan); + srslte::srslog_wrapper file_wrapper(*file_chan); + + // Start the log backend. + srslog::init(); // Instantiate file logger - srslte::logger_file logger_file; - srslte::logmap::set_default_logger(&logger_file); + srslte::logmap::set_default_logger(&file_wrapper); // Create UE object unique_ptr ue = std::unique_ptr(new ttcn3_ue()); // create and init SYSSIM - ttcn3_syssim syssim(&logger_file, ue.get()); + ttcn3_syssim syssim(file_wrapper, stdout_wrapper, ue.get()); if (syssim.init(ue_args) != SRSLTE_SUCCESS) { fprintf(stderr, "Error: Couldn't initialize system simulator\n"); return SRSLTE_ERROR; diff --git a/srsue/test/ttcn3/src/ttcn3_syssim.cc b/srsue/test/ttcn3/src/ttcn3_syssim.cc index 6a302a168..184232d7b 100644 --- a/srsue/test/ttcn3/src/ttcn3_syssim.cc +++ b/srsue/test/ttcn3/src/ttcn3_syssim.cc @@ -21,7 +21,9 @@ #include "srsue/test/ttcn3/hdr/ttcn3_syssim.h" #include "dut_utils.h" +#include "srslte/common/logger_srslog_wrapper.h" #include "srslte/mac/pdu_queue.h" +#include "srslte/srslog/srslog.h" #include "srslte/test/ue_test_interfaces.h" #include "srslte/upper/pdcp.h" #include "srslte/upper/rlc.h" @@ -35,13 +37,14 @@ #include "ttcn3_ut_interface.h" #include -ttcn3_syssim::ttcn3_syssim(srslte::logger_file* logger_file_, ttcn3_ue* ue_) : +ttcn3_syssim::ttcn3_syssim(srslte::logger& logger_file_, srslte::logger& logger_stdout_, ttcn3_ue* ue_) : log{"SS "}, mac_msg_ul(20, ss_mac_log), mac_msg_dl(20, ss_mac_log), pdus(128), - logger(logger_file_), + logger_stdout(logger_stdout_), logger_file(logger_file_), + logger_ptr(&logger_file_), pool(byte_buffer_pool::get_instance()), ue(ue_), rlc(ss_rlc_log->get_service_name().c_str()), @@ -49,7 +52,7 @@ ttcn3_syssim::ttcn3_syssim(srslte::logger_file* logger_file_, ttcn3_ue* ue_) : timer_handler(create_tti_timer(), [&](uint64_t res) { new_tti_indication(res); }), pdcp(&stack.task_sched, ss_pdcp_log->get_service_name().c_str()) { - if (ue->init(all_args_t{}, logger, this, "INIT_TEST") != SRSLTE_SUCCESS) { + if (ue->init(all_args_t{}, logger_ptr, this, "INIT_TEST") != SRSLTE_SUCCESS) { ue->stop(); fprintf(stderr, "Couldn't initialize UE.\n"); } @@ -63,20 +66,20 @@ int ttcn3_syssim::init(const all_args_t& args_) // Make sure to get SS logging as well if (args.log.filename == "stdout") { - logger = &logger_stdout; + logger_ptr = &logger_stdout; } - srslte::logmap::set_default_logger(logger); + srslte::logmap::set_default_logger(logger_ptr); // init and configure logging - srslte::logmap::register_log(std::unique_ptr{new log_filter{"SS ", logger, true}}); - ut_log.init("UT ", logger); - sys_log.init("SYS ", logger); - ip_sock_log.init("IP_S", logger); - ip_ctrl_log.init("IP_C", logger); - srb_log.init("SRB ", logger); - drb_log.init("DRB ", logger); - srslte::logmap::register_log(std::unique_ptr{new log_filter{"SS-RLC", logger}}); - srslte::logmap::register_log(std::unique_ptr{new log_filter{"SS-PDCP", logger}}); + srslte::logmap::register_log(std::unique_ptr{new log_filter{"SS ", logger_ptr, true}}); + ut_log.init("UT ", logger_ptr); + sys_log.init("SYS ", logger_ptr); + ip_sock_log.init("IP_S", logger_ptr); + ip_ctrl_log.init("IP_C", logger_ptr); + srb_log.init("SRB ", logger_ptr); + drb_log.init("DRB ", logger_ptr); + srslte::logmap::register_log(std::unique_ptr{new log_filter{"SS-RLC", logger_ptr}}); + srslte::logmap::register_log(std::unique_ptr{new log_filter{"SS-PDCP", logger_ptr}}); log->set_level(args.log.all_level); ut_log.set_level(args.log.all_level); @@ -405,10 +408,13 @@ void ttcn3_syssim::tc_start(const char* name) // set up logging if (args.log.filename == "stdout") { - logger = &logger_stdout; + logger_ptr = &logger_stdout; } else { - logger_file->init(get_filename_with_tc_name(local_args.log.filename, run_id, tc_name).c_str(), -1); - logger = logger_file; + const std::string& file_tc_name = get_filename_with_tc_name(local_args.log.filename, run_id, tc_name); + srslog::sink* s = srslog::create_file_sink(file_tc_name); + srslog::log_channel* c = srslog::create_log_channel(file_tc_name, *s); + test_case_logger = std::unique_ptr(new srslte::srslog_wrapper(*c)); + logger_ptr = test_case_logger.get(); } log->info("Initializing UE ID=%d for TC=%s\n", run_id, tc_name.c_str()); @@ -419,7 +425,7 @@ void ttcn3_syssim::tc_start(const char* name) local_args.stack.pcap.nas_filename = get_filename_with_tc_name(args.stack.pcap.nas_filename, run_id, tc_name); // bring up UE - if (ue->init(local_args, logger, this, tc_name)) { + if (ue->init(local_args, logger_ptr, this, tc_name)) { ue->stop(); std::string err("Couldn't initialize UE.\n"); log->error("%s\n", err.c_str()); @@ -444,8 +450,6 @@ void ttcn3_syssim::tc_end() // stop TTI timer del_epoll(timer_handler.get_timer_fd(), epoll_fd); - logger_file->stop(); - run_id++; // Reset SS' RLC and PDCP diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index d0ae1c512..1179c5c09 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -21,8 +21,10 @@ #include "srslte/common/bcd_helpers.h" #include "srslte/common/log_filter.h" +#include "srslte/common/logger_srslog_wrapper.h" #include "srslte/common/logmap.h" #include "srslte/interfaces/ue_interfaces.h" +#include "srslte/srslog/srslog.h" #include "srslte/test/ue_test_interfaces.h" #include "srslte/upper/pdcp.h" #include "srslte/upper/pdcp_entity_lte.h" @@ -269,6 +271,14 @@ int mme_attach_request_test() srslte::log_filter usim_log("USIM"); srslte::log_filter gw_log("GW"); + // Setup logging. + srslog::sink *log_sink = srslog::find_sink("stdout"); + srslog::log_channel* chan = srslog::create_log_channel("mme_attach_request_test", *log_sink); + srslte::srslog_wrapper log_wrapper(*chan); + + // Start the log backend. + srslog::init(); + rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); usim_log.set_level(srslte::LOG_LEVEL_DEBUG); gw_log.set_level(srslte::LOG_LEVEL_DEBUG); @@ -293,6 +303,7 @@ int mme_attach_request_test() nas_args_t nas_cfg; nas_cfg.force_imsi_attach = true; nas_cfg.apn_name = "test123"; + test_stack_dummy stack(&pdcp_dummy); srsue::nas nas(&stack.task_sched); srsue::gw gw; @@ -304,8 +315,8 @@ int mme_attach_request_test() gw_args.tun_dev_name = "tun0"; gw_args.log.gw_level = "debug"; gw_args.log.gw_hex_limit = 100000; - srslte::logger_stdout def_logstdout; - srslte::logger* logger = &def_logstdout; + + srslte::logger* logger = &log_wrapper; gw.init(gw_args, logger, &stack); stack.init(&nas);