Generalizing the main log interface

master
Paul Sutton 9 years ago
parent eb15eaeb01
commit 24b46906ba

@ -40,35 +40,42 @@
#ifndef LOG_H #ifndef LOG_H
#define 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 { 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 class log
{ {
public: 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 // This function shall be called at the start of every tti for printing tti
void step(uint32_t tti_) { void step(uint32_t tti_) {
tti = tti_; tti = tti_;
} }
typedef enum { void set_level(LOG_LEVEL_ENUM l) {
LOG_LEVEL_NONE = 0, level = l;
LOG_LEVEL_INFO,
LOG_LEVEL_DEBUG
} log_level_t;
void set_level_info() {
level = LOG_LEVEL_INFO;
} }
void set_level_debug() { LOG_LEVEL_ENUM get_level() {
level = LOG_LEVEL_DEBUG; return level;
} }
uint32_t get_tti() { uint32_t get_tti() {
@ -90,12 +97,12 @@ public:
protected: protected:
std::string get_service_name() { return service_name; } std::string get_service_name() { return service_name; }
uint32_t tti; uint32_t tti;
log_level_t level; LOG_LEVEL_ENUM level;
private: private:
std::string service_name; std::string service_name;
}; };
} } // namespace srslte
#endif #endif // LOG_H

@ -65,14 +65,11 @@ public:
void debug_line(string file, int line, string message, ...); void debug_line(string file, int line, string message, ...);
private: private:
typedef enum { void printlog(LOG_LEVEL_ENUM level, uint32_t tti, string file, int line, string message, va_list args);
ERROR=0, WARNING, INFO, DEBUG, NOF_LEVELS void printlog(LOG_LEVEL_ENUM level, uint32_t tti, string message, va_list args);
} 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);
}; };
} } // namespace srslte
#endif #endif // LOGSTDOUT_H

@ -37,19 +37,14 @@ using namespace std;
namespace srslte { namespace srslte {
const char* level_str[4] = {"[ERROR ", void log_stdout::printlog(LOG_LEVEL_ENUM level, uint32_t tti, string msg, va_list args) {
"[WARN ",
"[INFO ",
"[DEBUG "};
void log_stdout::printlog(level_t type, uint32_t tti, string msg, va_list args) { printlog(level, tti, string(), -1, msg, args);
printlog(type, 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) { if (file.length() > 0) {
printf("/%-14s", file.substr(file.find_last_of("/")+1,file.find_last_of(".")-1-file.find_last_of("/")).c_str()); printf("/%-14s", file.substr(file.find_last_of("/")+1,file.find_last_of(".")-1-file.find_last_of("/")).c_str());
} }
@ -61,77 +56,87 @@ void log_stdout::printlog(level_t type, uint32_t tti, string file, int line, str
void log_stdout::error(string msg, ...) void log_stdout::error(string msg, ...)
{ {
if (level >= LOG_LEVEL_ERROR) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
printlog(ERROR, tti, msg, args); printlog(LOG_LEVEL_ERROR, tti, msg, args);
va_end(args); va_end(args);
} }
}
void log_stdout::info(string msg, ...) void log_stdout::warning(string msg, ...)
{ {
if (level >= LOG_LEVEL_INFO) { if (level >= LOG_LEVEL_WARNING) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
printlog(INFO, tti, msg, args); printlog(LOG_LEVEL_WARNING, tti, msg, args);
va_end(args); va_end(args);
} }
} }
void log_stdout::debug(string msg, ...) void log_stdout::info(string msg, ...)
{ {
if (level >= LOG_LEVEL_DEBUG) { if (level >= LOG_LEVEL_INFO) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
printlog(DEBUG, tti, msg, args); printlog(LOG_LEVEL_INFO, tti, msg, args);
va_end(args); va_end(args);
} }
} }
void log_stdout::warning(string msg, ...) void log_stdout::debug(string msg, ...)
{ {
if (level >= LOG_LEVEL_DEBUG) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
printlog(WARNING, tti, msg, args); printlog(LOG_LEVEL_DEBUG, tti, msg, args);
va_end(args); va_end(args);
} }
}
void log_stdout::error_line(string file, int line, string msg, ...) void log_stdout::error_line(string file, int line, string msg, ...)
{ {
if (level >= LOG_LEVEL_ERROR) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
printlog(ERROR, tti, file, line, msg, args); printlog(LOG_LEVEL_ERROR, tti, file, line, msg, args);
va_end(args); va_end(args);
} }
}
void log_stdout::info_line(string file, int line, string msg, ...) void log_stdout::warning_line(string file, int line, string msg, ...)
{ {
if (level >= LOG_LEVEL_INFO) { if (level >= LOG_LEVEL_WARNING) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
printlog(INFO, tti, file, line, msg, args); printlog(LOG_LEVEL_WARNING, tti, file, line, msg, args);
va_end(args); va_end(args);
} }
} }
void log_stdout::debug_line(string file, int line, string msg, ...) void log_stdout::info_line(string file, int line, string msg, ...)
{ {
if (level >= LOG_LEVEL_DEBUG) { if (level >= LOG_LEVEL_INFO) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
printlog(DEBUG, tti, file, line, msg, args); printlog(LOG_LEVEL_INFO, tti, file, line, msg, args);
va_end(args); va_end(args);
} }
} }
void log_stdout::warning_line(string file, int line, string msg, ...) void log_stdout::debug_line(string file, int line, string msg, ...)
{ {
if (level >= LOG_LEVEL_DEBUG) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
printlog(WARNING, tti, file, line, msg, args); printlog(LOG_LEVEL_DEBUG, tti, file, line, msg, args);
va_end(args); va_end(args);
} }
} }
} // namespace srslte

@ -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/mac.h"
#include "srsapps/ue/mac/demux.h" #include "srsapps/ue/mac/demux.h"

@ -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/phy.h"
#include "srsapps/ue/phy/dl_sched_grant.h" #include "srsapps/ue/phy/dl_sched_grant.h"

@ -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 <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <pthread.h> #include <pthread.h>

@ -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/mux.h"
#include "srsapps/ue/mac/mac.h" #include "srsapps/ue/mac/mac.h"

@ -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/proc_bsr.h"
#include "srsapps/ue/mac/mac_params.h" #include "srsapps/ue/mac/mac_params.h"
#include "srsapps/ue/mac/mac.h" #include "srsapps/ue/mac/mac.h"

@ -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 <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>

@ -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/proc_sr.h"
#include "srsapps/ue/mac/mac_params.h" #include "srsapps/ue/mac/mac_params.h"

@ -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/phy.h"
#include "srsapps/common/log.h" #include "srsapps/common/log.h"

@ -344,12 +344,12 @@ int main(int argc, char *argv[])
switch (prog_args.verbose) { switch (prog_args.verbose) {
case 1: case 1:
mac_log.set_level_info(); mac_log.set_level(srslte::LOG_LEVEL_INFO);
phy_log.set_level_info(); phy_log.set_level(srslte::LOG_LEVEL_INFO);
break; break;
case 2: case 2:
mac_log.set_level_debug(); mac_log.set_level(srslte::LOG_LEVEL_DEBUG);
phy_log.set_level_debug(); phy_log.set_level(srslte::LOG_LEVEL_DEBUG);
break; break;
} }

@ -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 <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <pthread.h> #include <pthread.h>

@ -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 <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <pthread.h> #include <pthread.h>

@ -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 <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <pthread.h> #include <pthread.h>

@ -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 <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <pthread.h> #include <pthread.h>

Loading…
Cancel
Save