diff --git a/srsapps/common/include/srsapps/common/log.h b/srsapps/common/include/srsapps/common/log.h index 3dfab5e1e..0d269b07b 100644 --- a/srsapps/common/include/srsapps/common/log.h +++ b/srsapps/common/include/srsapps/common/log.h @@ -40,35 +40,42 @@ #ifndef LOG_H #define LOG_H -#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) - namespace srslte { - + +typedef enum { + LOG_LEVEL_NONE = 0, + LOG_LEVEL_ERROR, + LOG_LEVEL_WARNING, + LOG_LEVEL_INFO, + LOG_LEVEL_DEBUG, + LOG_LEVEL_N_ITEMS +} LOG_LEVEL_ENUM; +static const char log_level_text[LOG_LEVEL_N_ITEMS][16] = {"None", + "Error", + "Warning", + "Info", + "Debug"}; + class log { public: - log(std::string service_name_) { service_name = service_name_; tti = 0; level = LOG_LEVEL_NONE; } + log(std::string service_name_) { + service_name = service_name_; + tti = 0; + level = LOG_LEVEL_NONE; + } // This function shall be called at the start of every tti for printing tti void step(uint32_t tti_) { tti = tti_; } - typedef enum { - LOG_LEVEL_NONE = 0, - LOG_LEVEL_INFO, - LOG_LEVEL_DEBUG - } log_level_t; - - void set_level_info() { - level = LOG_LEVEL_INFO; + void set_level(LOG_LEVEL_ENUM l) { + level = l; } - void set_level_debug() { - level = LOG_LEVEL_DEBUG; + LOG_LEVEL_ENUM get_level() { + return level; } uint32_t get_tti() { @@ -90,12 +97,12 @@ public: protected: std::string get_service_name() { return service_name; } uint32_t tti; - log_level_t level; + LOG_LEVEL_ENUM level; private: std::string service_name; }; -} +} // namespace srslte -#endif +#endif // LOG_H diff --git a/srsapps/common/include/srsapps/common/log_stdout.h b/srsapps/common/include/srsapps/common/log_stdout.h index 89408c60a..73173e3d1 100644 --- a/srsapps/common/include/srsapps/common/log_stdout.h +++ b/srsapps/common/include/srsapps/common/log_stdout.h @@ -65,14 +65,11 @@ public: void debug_line(string file, int line, string message, ...); private: - typedef enum { - ERROR=0, WARNING, INFO, DEBUG, NOF_LEVELS - } level_t; - void printlog(level_t level, uint32_t tti, string file, int line, string message, va_list args); - void printlog(level_t level, uint32_t tti, string message, va_list args); + void printlog(LOG_LEVEL_ENUM level, uint32_t tti, string file, int line, string message, va_list args); + void printlog(LOG_LEVEL_ENUM level, uint32_t tti, string message, va_list args); }; -} +} // namespace srslte -#endif +#endif // LOGSTDOUT_H diff --git a/srsapps/common/src/log_stdout.cc b/srsapps/common/src/log_stdout.cc index c8422197d..688320457 100644 --- a/srsapps/common/src/log_stdout.cc +++ b/srsapps/common/src/log_stdout.cc @@ -37,19 +37,14 @@ using namespace std; namespace srslte { -const char* level_str[4] = {"[ERROR ", - "[WARN ", - "[INFO ", - "[DEBUG "}; +void log_stdout::printlog(LOG_LEVEL_ENUM level, uint32_t tti, string msg, va_list args) { -void log_stdout::printlog(level_t type, uint32_t tti, string msg, va_list args) { - - printlog(type, tti, string(), -1, msg, args); + printlog(level, tti, string(), -1, msg, args); } -void log_stdout::printlog(level_t type, uint32_t tti, string file, int line, string msg, va_list args) { +void log_stdout::printlog(LOG_LEVEL_ENUM level, uint32_t tti, string file, int line, string msg, va_list args) { - printf("%s %s",level_str[type], get_service_name().c_str()); + printf("%s %s",log_level_text[level], get_service_name().c_str()); if (file.length() > 0) { printf("/%-14s", file.substr(file.find_last_of("/")+1,file.find_last_of(".")-1-file.find_last_of("/")).c_str()); } @@ -61,10 +56,22 @@ void log_stdout::printlog(level_t type, uint32_t tti, string file, int line, str void log_stdout::error(string msg, ...) { - va_list args; - va_start(args, msg); - printlog(ERROR, tti, msg, args); - va_end(args); + if (level >= LOG_LEVEL_ERROR) { + va_list args; + va_start(args, msg); + printlog(LOG_LEVEL_ERROR, tti, msg, args); + va_end(args); + } +} + +void log_stdout::warning(string msg, ...) +{ + if (level >= LOG_LEVEL_WARNING) { + va_list args; + va_start(args, msg); + printlog(LOG_LEVEL_WARNING, tti, msg, args); + va_end(args); + } } void log_stdout::info(string msg, ...) @@ -72,7 +79,7 @@ void log_stdout::info(string msg, ...) if (level >= LOG_LEVEL_INFO) { va_list args; va_start(args, msg); - printlog(INFO, tti, msg, args); + printlog(LOG_LEVEL_INFO, tti, msg, args); va_end(args); } } @@ -82,26 +89,32 @@ void log_stdout::debug(string msg, ...) if (level >= LOG_LEVEL_DEBUG) { va_list args; va_start(args, msg); - printlog(DEBUG, tti, msg, args); + printlog(LOG_LEVEL_DEBUG, tti, msg, args); va_end(args); } } -void log_stdout::warning(string msg, ...) -{ - va_list args; - va_start(args, msg); - printlog(WARNING, tti, msg, args); - va_end(args); -} + void log_stdout::error_line(string file, int line, string msg, ...) { - va_list args; - va_start(args, msg); - printlog(ERROR, tti, file, line, msg, args); - va_end(args); + if (level >= LOG_LEVEL_ERROR) { + va_list args; + va_start(args, msg); + printlog(LOG_LEVEL_ERROR, tti, file, line, msg, args); + va_end(args); + } +} + +void log_stdout::warning_line(string file, int line, string msg, ...) +{ + if (level >= LOG_LEVEL_WARNING) { + va_list args; + va_start(args, msg); + printlog(LOG_LEVEL_WARNING, tti, file, line, msg, args); + va_end(args); + } } void log_stdout::info_line(string file, int line, string msg, ...) @@ -109,7 +122,7 @@ void log_stdout::info_line(string file, int line, string msg, ...) if (level >= LOG_LEVEL_INFO) { va_list args; va_start(args, msg); - printlog(INFO, tti, file, line, msg, args); + printlog(LOG_LEVEL_INFO, tti, file, line, msg, args); va_end(args); } } @@ -119,19 +132,11 @@ void log_stdout::debug_line(string file, int line, string msg, ...) if (level >= LOG_LEVEL_DEBUG) { va_list args; va_start(args, msg); - printlog(DEBUG, tti, file, line, msg, args); + printlog(LOG_LEVEL_DEBUG, tti, file, line, msg, args); va_end(args); } } -void log_stdout::warning_line(string file, int line, string msg, ...) -{ - va_list args; - va_start(args, msg); - printlog(WARNING, tti, file, line, msg, args); - va_end(args); -} - -} +} // namespace srslte - \ No newline at end of file + diff --git a/srsapps/ue/mac/src/demux.cc b/srsapps/ue/mac/src/demux.cc index 9459df282..a73352ceb 100644 --- a/srsapps/ue/mac/src/demux.cc +++ b/srsapps/ue/mac/src/demux.cc @@ -25,6 +25,10 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) #include "srsapps/ue/mac/mac.h" #include "srsapps/ue/mac/demux.h" diff --git a/srsapps/ue/mac/src/dl_harq.cc b/srsapps/ue/mac/src/dl_harq.cc index f84e0f586..3b3478a7b 100644 --- a/srsapps/ue/mac/src/dl_harq.cc +++ b/srsapps/ue/mac/src/dl_harq.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include "srsapps/ue/phy/phy.h" #include "srsapps/ue/phy/dl_sched_grant.h" @@ -254,4 +259,4 @@ bool dl_harq_entity::dl_harq_process::init(srslte_cell_t cell, uint32_t max_payl } -} \ No newline at end of file +} diff --git a/srsapps/ue/mac/src/mac.cc b/srsapps/ue/mac/src/mac.cc index 0c929e3a9..f48291d5d 100644 --- a/srsapps/ue/mac/src/mac.cc +++ b/srsapps/ue/mac/src/mac.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include #include #include diff --git a/srsapps/ue/mac/src/mux.cc b/srsapps/ue/mac/src/mux.cc index e6935682e..0d300f295 100644 --- a/srsapps/ue/mac/src/mux.cc +++ b/srsapps/ue/mac/src/mux.cc @@ -25,6 +25,10 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) #include "srsapps/ue/mac/mux.h" #include "srsapps/ue/mac/mac.h" diff --git a/srsapps/ue/mac/src/proc_bsr.cc b/srsapps/ue/mac/src/proc_bsr.cc index 6e2700bcd..a4dce88f7 100644 --- a/srsapps/ue/mac/src/proc_bsr.cc +++ b/srsapps/ue/mac/src/proc_bsr.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include "srsapps/ue/mac/proc_bsr.h" #include "srsapps/ue/mac/mac_params.h" #include "srsapps/ue/mac/mac.h" diff --git a/srsapps/ue/mac/src/proc_ra.cc b/srsapps/ue/mac/src/proc_ra.cc index b2f849275..fd4ed3a20 100644 --- a/srsapps/ue/mac/src/proc_ra.cc +++ b/srsapps/ue/mac/src/proc_ra.cc @@ -25,6 +25,10 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) #include #include diff --git a/srsapps/ue/mac/src/proc_sr.cc b/srsapps/ue/mac/src/proc_sr.cc index f0140e957..83e876b5c 100644 --- a/srsapps/ue/mac/src/proc_sr.cc +++ b/srsapps/ue/mac/src/proc_sr.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include "srsapps/ue/mac/proc_sr.h" #include "srsapps/ue/mac/mac_params.h" diff --git a/srsapps/ue/mac/src/ul_harq.cc b/srsapps/ue/mac/src/ul_harq.cc index 3d8bf69ad..2b5b98009 100644 --- a/srsapps/ue/mac/src/ul_harq.cc +++ b/srsapps/ue/mac/src/ul_harq.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include "srsapps/ue/phy/phy.h" #include "srsapps/common/log.h" @@ -296,4 +301,4 @@ uint32_t ul_harq_entity::ul_harq_process::last_tx_tti() } -} \ No newline at end of file +} diff --git a/srsapps/ue/mac/test/mac_test.cc b/srsapps/ue/mac/test/mac_test.cc index 8dede5467..8bf0237df 100644 --- a/srsapps/ue/mac/test/mac_test.cc +++ b/srsapps/ue/mac/test/mac_test.cc @@ -344,12 +344,12 @@ int main(int argc, char *argv[]) switch (prog_args.verbose) { case 1: - mac_log.set_level_info(); - phy_log.set_level_info(); + mac_log.set_level(srslte::LOG_LEVEL_INFO); + phy_log.set_level(srslte::LOG_LEVEL_INFO); break; case 2: - mac_log.set_level_debug(); - phy_log.set_level_debug(); + mac_log.set_level(srslte::LOG_LEVEL_DEBUG); + phy_log.set_level(srslte::LOG_LEVEL_DEBUG); break; } diff --git a/srsapps/ue/phy/src/dl_buffer.cc b/srsapps/ue/phy/src/dl_buffer.cc index 1152a4795..215b9c35d 100644 --- a/srsapps/ue/phy/src/dl_buffer.cc +++ b/srsapps/ue/phy/src/dl_buffer.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include #include #include diff --git a/srsapps/ue/phy/src/phy.cc b/srsapps/ue/phy/src/phy.cc index 6e945aa63..f3862bcfa 100644 --- a/srsapps/ue/phy/src/phy.cc +++ b/srsapps/ue/phy/src/phy.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include #include #include diff --git a/srsapps/ue/phy/src/prach.cc b/srsapps/ue/phy/src/prach.cc index c184b7520..46cce974d 100644 --- a/srsapps/ue/phy/src/prach.cc +++ b/srsapps/ue/phy/src/prach.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include #include #include diff --git a/srsapps/ue/phy/src/ul_buffer.cc b/srsapps/ue/phy/src/ul_buffer.cc index 9f897d68e..3f1154090 100644 --- a/srsapps/ue/phy/src/ul_buffer.cc +++ b/srsapps/ue/phy/src/ul_buffer.cc @@ -25,6 +25,11 @@ * */ +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) + #include #include #include