Generalizing the main log interface

master
Paul Sutton 10 years ago
parent eb15eaeb01
commit 24b46906ba

@ -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

@ -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

@ -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

@ -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"

@ -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
}
}
}

@ -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 <strings.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/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/mac_params.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 <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/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/common/log.h"
@ -296,4 +301,4 @@ uint32_t ul_harq_entity::ul_harq_process::last_tx_tti()
}
}
}

@ -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;
}

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

Loading…
Cancel
Save