diff --git a/lib/include/srslte/common/log_helper.h b/lib/include/srslte/common/log_helper.h new file mode 100644 index 000000000..4cb6cd66c --- /dev/null +++ b/lib/include/srslte/common/log_helper.h @@ -0,0 +1,67 @@ +/* + * 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/. + * + */ + +#ifndef SRSLTE_LOG_HELPER_H +#define SRSLTE_LOG_HELPER_H + +/** + * @file log_helper.h + * + * Convenience macro to log formatted messages. It is checked if the log pointer is still valid before accessing it. + */ + +namespace srslte { + +#define Error(fmt, ...) \ + do { \ + if (log_h.get() != nullptr) { \ + log_h->error(fmt, ##__VA_ARGS__); \ + } \ + } while (0) +#define Warning(fmt, ...) \ + do { \ + if (log_h.get() != nullptr) { \ + log_h->warning(fmt, ##__VA_ARGS__); \ + } \ + } while (0) +#define Info(fmt, ...) \ + do { \ + if (log_h.get() != nullptr) { \ + log_h->info(fmt, ##__VA_ARGS__); \ + } \ + } while (0) +#define Debug(fmt, ...) \ + do { \ + if (log_h.get() != nullptr) { \ + log_h->debug(fmt, ##__VA_ARGS__); \ + } \ + } while (0) + +#define Console(fmt, ...) \ + do { \ + if (log_h.get() != nullptr) { \ + log_h->console(fmt, ##__VA_ARGS__); \ + } \ + } while (0) + +} // namespace srslte + +#endif // SRSLTE_LOG_HELPER_H diff --git a/lib/src/common/pdu_queue.cc b/lib/src/common/pdu_queue.cc index b81fb38dc..897a3ea82 100644 --- a/lib/src/common/pdu_queue.cc +++ b/lib/src/common/pdu_queue.cc @@ -19,12 +19,8 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - #include "srslte/common/pdu_queue.h" +#include "srslte/common/log_helper.h" namespace srslte { diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index fd3c64f4a..640eaed6e 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -19,11 +19,6 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - #include #include #include @@ -32,6 +27,7 @@ #include "srsenb/hdr/stack/mac/mac.h" #include "srslte/common/log.h" +#include "srslte/common/log_helper.h" #include "srslte/common/rwlock_guard.h" #include "srslte/common/time_prof.h" diff --git a/srsenb/src/stack/mac/scheduler.cc b/srsenb/src/stack/mac/scheduler.cc index 80199b1eb..39002e9e2 100644 --- a/srsenb/src/stack/mac/scheduler.cc +++ b/srsenb/src/stack/mac/scheduler.cc @@ -25,14 +25,10 @@ #include "srsenb/hdr/stack/mac/scheduler.h" #include "srsenb/hdr/stack/mac/scheduler_carrier.h" #include "srslte/common/logmap.h" -#include "srslte/common/pdu.h" #include "srslte/srslte.h" #define Console(fmt, ...) srslte::logmap::get("MAC ")->console(fmt, ##__VA_ARGS__) #define Error(fmt, ...) srslte::logmap::get("MAC ")->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) namespace srsenb { diff --git a/srsenb/src/stack/mac/scheduler_carrier.cc b/srsenb/src/stack/mac/scheduler_carrier.cc index 07c829eb5..aaa104448 100644 --- a/srsenb/src/stack/mac/scheduler_carrier.cc +++ b/srsenb/src/stack/mac/scheduler_carrier.cc @@ -21,13 +21,9 @@ #include "srsenb/hdr/stack/mac/scheduler_carrier.h" #include "srsenb/hdr/stack/mac/scheduler_metric.h" +#include "srslte/common/log_helper.h" #include "srslte/common/logmap.h" -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - namespace srsenb { /******************************************************* diff --git a/srsenb/src/stack/mac/scheduler_grid.cc b/srsenb/src/stack/mac/scheduler_grid.cc index 96b1d0451..7d5092b04 100644 --- a/srsenb/src/stack/mac/scheduler_grid.cc +++ b/srsenb/src/stack/mac/scheduler_grid.cc @@ -21,14 +21,10 @@ #include "srsenb/hdr/stack/mac/scheduler_grid.h" #include "srsenb/hdr/stack/mac/scheduler.h" +#include "srslte/common/log_helper.h" #include "srslte/common/logmap.h" #include -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - namespace srsenb { const char* alloc_outcome_t::to_string() const diff --git a/srsenb/src/stack/mac/scheduler_harq.cc b/srsenb/src/stack/mac/scheduler_harq.cc index 0f8617258..185ae1eb5 100644 --- a/srsenb/src/stack/mac/scheduler_harq.cc +++ b/srsenb/src/stack/mac/scheduler_harq.cc @@ -22,14 +22,10 @@ #include #include "srsenb/hdr/stack/mac/scheduler.h" +#include "srslte/common/log_helper.h" #include "srslte/common/pdu.h" #include "srslte/srslte.h" -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - using srslte::tti_point; namespace srsenb { diff --git a/srsenb/src/stack/mac/scheduler_metric.cc b/srsenb/src/stack/mac/scheduler_metric.cc index ffdc50bbc..47d666db5 100644 --- a/srsenb/src/stack/mac/scheduler_metric.cc +++ b/srsenb/src/stack/mac/scheduler_metric.cc @@ -21,14 +21,10 @@ #include "srsenb/hdr/stack/mac/scheduler_metric.h" #include "srsenb/hdr/stack/mac/scheduler_harq.h" +#include "srslte/common/log_helper.h" #include "srslte/common/logmap.h" #include -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - namespace srsenb { /***************************************************************** diff --git a/srsenb/src/stack/mac/scheduler_ue.cc b/srsenb/src/stack/mac/scheduler_ue.cc index b0ea69fa8..055c8f678 100644 --- a/srsenb/src/stack/mac/scheduler_ue.cc +++ b/srsenb/src/stack/mac/scheduler_ue.cc @@ -23,15 +23,11 @@ #include "srsenb/hdr/stack/mac/scheduler.h" #include "srsenb/hdr/stack/mac/scheduler_ue.h" +#include "srslte/common/log_helper.h" #include "srslte/common/logmap.h" #include "srslte/common/pdu.h" #include "srslte/srslte.h" -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - /****************************************************** * UE class * ******************************************************/ diff --git a/srsenb/src/stack/mac/ue.cc b/srsenb/src/stack/mac/ue.cc index 53da675b5..0722b281a 100644 --- a/srsenb/src/stack/mac/ue.cc +++ b/srsenb/src/stack/mac/ue.cc @@ -25,13 +25,9 @@ #include #include "srsenb/hdr/stack/mac/ue.h" +#include "srslte/common/log_helper.h" #include "srslte/interfaces/enb_interfaces.h" -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - namespace srsenb { ue::ue(uint16_t rnti_, diff --git a/srsue/hdr/stack/mac/ul_harq.h b/srsue/hdr/stack/mac/ul_harq.h index 39cbe7fff..6bb89b921 100644 --- a/srsue/hdr/stack/mac/ul_harq.h +++ b/srsue/hdr/stack/mac/ul_harq.h @@ -22,11 +22,6 @@ #ifndef SRSUE_UL_HARQ_H #define SRSUE_UL_HARQ_H -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - #include "mux.h" #include "proc_ra.h" #include "srslte/common/interfaces_common.h" diff --git a/srsue/src/stack/mac/proc_bsr.cc b/srsue/src/stack/mac/proc_bsr.cc index f14c92a2e..28bffc507 100644 --- a/srsue/src/stack/mac/proc_bsr.cc +++ b/srsue/src/stack/mac/proc_bsr.cc @@ -19,13 +19,8 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - #include "srsue/hdr/stack/mac/proc_bsr.h" -#include "srsue/hdr/stack/mac/mac.h" +#include "srslte/common/log_helper.h" #include "srsue/hdr/stack/mac/mux.h" namespace srsue { diff --git a/srsue/src/stack/mac/proc_ra.cc b/srsue/src/stack/mac/proc_ra.cc index fe5071d33..e83cd3757 100644 --- a/srsue/src/stack/mac/proc_ra.cc +++ b/srsue/src/stack/mac/proc_ra.cc @@ -19,20 +19,13 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - +#include "srsue/hdr/stack/mac/proc_ra.h" +#include "srslte/common/log_helper.h" +#include "srsue/hdr/stack/mac/mux.h" #include // for printing uint64_t -#include #include #include -#include "srsue/hdr/stack/mac/mac.h" -#include "srsue/hdr/stack/mac/mux.h" -#include "srsue/hdr/stack/mac/proc_ra.h" - /* Random access procedure as specified in Section 5.1 of 36.321 */ namespace srsue {