Commit 2d4e3a05 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/simplify-log-module-interface' into integration_2024_w10

parents 132949c2 24d30ae7
...@@ -46,7 +46,9 @@ ...@@ -46,7 +46,9 @@
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <stdatomic.h> #include <stdatomic.h>
#include "common/utils/LOG/log_extern.h" #include "common/utils/LOG/log.h"
#define LOG_MEM_SIZE 100*1024*1024
// main log variables // main log variables
...@@ -58,53 +60,105 @@ void read_cpu_hardware (void) __attribute__ ((constructor)); ...@@ -58,53 +60,105 @@ void read_cpu_hardware (void) __attribute__ ((constructor));
void read_cpu_hardware (void) {} void read_cpu_hardware (void) {}
#endif #endif
log_mem_cnt_t log_mem_d[2];
int log_mem_flag = 0; typedef struct {
char* buf_p;
int buf_index;
int enable_flag;
} log_mem_cnt_t;
static log_mem_cnt_t log_mem_d[2];
static int log_mem_flag = 0;
volatile int log_mem_side=0; volatile int log_mem_side=0;
pthread_mutex_t log_mem_lock; static pthread_mutex_t log_mem_lock;
pthread_cond_t log_mem_notify; static pthread_cond_t log_mem_notify;
pthread_t log_mem_thread; static pthread_t log_mem_thread;
int log_mem_file_cnt=0; static int log_mem_file_cnt=0;
volatile int log_mem_write_flag=0; volatile int log_mem_write_flag=0;
volatile int log_mem_write_side=0; volatile int log_mem_write_side=0;
char __log_mem_filename[1024]={0}; static char * log_mem_filename;
char * log_mem_filename = &__log_mem_filename[0];
char logmem_filename[1024] = {0};
const mapping log_level_names[] = {{"error", OAILOG_ERR}, static mapping log_level_names[] = {{"error", OAILOG_ERR},
{"warn", OAILOG_WARNING}, {"warn", OAILOG_WARNING},
{"analysis", OAILOG_ANALYSIS}, {"analysis", OAILOG_ANALYSIS},
{"info", OAILOG_INFO}, {"info", OAILOG_INFO},
{"debug", OAILOG_DEBUG}, {"debug", OAILOG_DEBUG},
{"trace", OAILOG_TRACE}, {"trace", OAILOG_TRACE},
{NULL, -1}}; {NULL, -1}};
mapping * log_level_names_ptr(void)
{
return log_level_names;
}
const mapping log_options[] = {{"nocolor", FLAG_NOCOLOR},
{"level", FLAG_LEVEL},
{"thread", FLAG_THREAD},
{"line_num", FLAG_FILE_LINE},
{"function", FLAG_FUNCT},
{"time", FLAG_TIME},
{"thread_id", FLAG_THREAD_ID},
{"wall_clock", FLAG_REAL_TIME},
{NULL, -1}};
const mapping log_maskmap[] = LOG_MASKMAP_INIT; /** @defgroup _log_format Defined log format
* @ingroup _macro
* @brief Macro of log formats defined by LOG
* @{*/
static const unsigned int FLAG_NOCOLOR = 1; /*!< \brief use colors in log messages, depending on level */
static const unsigned int FLAG_THREAD = 1 << 1; /*!< \brief display thread name in log messages */
static const unsigned int FLAG_LEVEL = 1 << 2; /*!< \brief display log level in log messages */
static const unsigned int FLAG_FUNCT = 1 << 3;
static const unsigned int FLAG_FILE_LINE = 1 << 4;
static const unsigned int FLAG_TIME = 1 << 5;
static const unsigned int FLAG_THREAD_ID = 1 << 6;
static const unsigned int FLAG_REAL_TIME = 1 << 7;
static const unsigned int FLAG_INITIALIZED = 1 << 8;
/** @}*/
static mapping log_options[] = {{"nocolor", FLAG_NOCOLOR},
{"level", FLAG_LEVEL},
{"thread", FLAG_THREAD},
{"line_num", FLAG_FILE_LINE},
{"function", FLAG_FUNCT},
{"time", FLAG_TIME},
{"thread_id", FLAG_THREAD_ID},
{"wall_clock", FLAG_REAL_TIME},
{NULL, -1}};
mapping * log_option_names_ptr(void)
{
return log_options;
}
static mapping log_maskmap[] = {{"PRACH", DEBUG_PRACH},
{"RU", DEBUG_RU},
{"UE_PHYPROC", DEBUG_UE_PHYPROC},
{"LTEESTIM", DEBUG_LTEESTIM},
{"DLCELLSPEC", DEBUG_DLCELLSPEC},
{"ULSCH", DEBUG_ULSCH},
{"RRC", DEBUG_RRC},
{"PDCP", DEBUG_PDCP},
{"DFT", DEBUG_DFT},
{"ASN1", DEBUG_ASN1},
{"CTRLSOCKET", DEBUG_CTRLSOCKET},
{"SECURITY", DEBUG_SECURITY},
{"NAS", DEBUG_NAS},
{"RLC", DEBUG_RLC},
{"DLSCH_DECOD", DEBUG_DLSCH_DECOD},
{"UE_TIMING", UE_TIMING},
{NULL, -1}};
mapping * log_maskmap_ptr(void)
{
return log_maskmap;
}
/* .log_format = 0x13 uncolored standard messages
* .log_format = 0x93 colored standard messages */
/* keep white space in first position; switching it to 0 allows colors to be disabled*/
static const char *const LOG_RED = "\033[1;31m"; /*!< \brief VT100 sequence for bold red foreground */
static const char *const LOG_GREEN = "\033[32m"; /*!< \brief VT100 sequence for green foreground */
static const char *const LOG_ORANGE = "\033[93m"; /*!< \brief VT100 sequence for orange foreground */
static const char *const LOG_BLUE = "\033[34m"; /*!< \brief VT100 sequence for blue foreground */
static const char *const LOG_CYBL = "\033[40;36m"; /*!< \brief VT100 sequence for cyan foreground on black background */
static const char *const LOG_RESET = "\033[0m"; /*!< \brief VT100 sequence for reset (black) foreground */
static const char *const log_level_highlight_start[] = static const char *const log_level_highlight_start[] =
{LOG_RED, LOG_ORANGE, LOG_GREEN, "", LOG_BLUE, LOG_CYBL}; /*!< \brief Optional start-format strings for highlighting */ {LOG_RED, LOG_ORANGE, LOG_GREEN, "", LOG_BLUE, LOG_CYBL}; /*!< \brief Optional start-format strings for highlighting */
static const char *const log_level_highlight_end[] = static const char *const log_level_highlight_end[] =
{LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET}; /*!< \brief Optional end-format strings for highlighting */ {LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET}; /*!< \brief Optional end-format strings for highlighting */
static void log_output_memory(log_component_t *c, const char *file, const char *func, int line, int comp, int level, const char* format,va_list args); static void log_output_memory(log_component_t *c, const char *file, const char *func, int line, int comp, int level, const char* format,va_list args);
int write_file_matlab(const char *fname, const char *vname, void *data, int length, int dec, unsigned int format, int multiVec)
int write_file_matlab(const char *fname,
const char *vname,
void *data,
int length,
int dec,
unsigned int format,
int multiVec)
{ {
FILE *fp=NULL; FILE *fp=NULL;
int i; int i;
...@@ -274,15 +328,15 @@ int write_file_matlab(const char *fname, ...@@ -274,15 +328,15 @@ int write_file_matlab(const char *fname,
} }
/* get log parameters from configuration file */ /* get log parameters from configuration file */
void log_getconfig(log_t *g_log) void log_getconfig(log_t *g_log)
{ {
char *gloglevel = NULL; char *gloglevel = NULL;
int consolelog = 0; int consolelog = 0;
paramdef_t logparams_defaults[] = LOG_GLOBALPARAMS_DESC; paramdef_t logparams_defaults[] = LOG_GLOBALPARAMS_DESC;
paramdef_t logparams_level[MAX_LOG_PREDEF_COMPONENTS]; paramdef_t logparams_level[MAX_LOG_PREDEF_COMPONENTS];
paramdef_t logparams_logfile[MAX_LOG_PREDEF_COMPONENTS]; paramdef_t logparams_logfile[MAX_LOG_PREDEF_COMPONENTS];
paramdef_t logparams_debug[sizeof(log_maskmap)/sizeof(mapping)]; paramdef_t logparams_debug[sizeofArray(log_maskmap)];
paramdef_t logparams_dump[sizeof(log_maskmap)/sizeof(mapping)]; paramdef_t logparams_dump[sizeofArray(log_maskmap)];
int ret = config_get(config_get_if(), logparams_defaults, sizeofArray(logparams_defaults), CONFIG_STRING_LOG_PREFIX); int ret = config_get(config_get_if(), logparams_defaults, sizeofArray(logparams_defaults), CONFIG_STRING_LOG_PREFIX);
if (ret <0) { if (ret <0) {
...@@ -304,10 +358,10 @@ void log_getconfig(log_t *g_log) ...@@ -304,10 +358,10 @@ void log_getconfig(log_t *g_log)
} }
/* build the parameter array for setting per component log level and infile options */ /* build the parameter array for setting per component log level and infile options */
memset(logparams_level, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); memset(logparams_level, 0, sizeof(logparams_level));
memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); memset(logparams_logfile, 0, sizeof(logparams_logfile));
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) { for (int i = 0; i < MAX_LOG_PREDEF_COMPONENTS; i++) {
if(g_log->log_component[i].name == NULL) { if(g_log->log_component[i].name == NULL) {
g_log->log_component[i].name = malloc(17); g_log->log_component[i].name = malloc(17);
sprintf((char *)g_log->log_component[i].name,"comp%i?",i); sprintf((char *)g_log->log_component[i].name,"comp%i?",i);
...@@ -341,11 +395,11 @@ void log_getconfig(log_t *g_log) ...@@ -341,11 +395,11 @@ void log_getconfig(log_t *g_log)
config_get(config_get_if(), logparams_logfile, MAX_LOG_PREDEF_COMPONENTS, CONFIG_STRING_LOG_PREFIX); config_get(config_get_if(), logparams_logfile, MAX_LOG_PREDEF_COMPONENTS, CONFIG_STRING_LOG_PREFIX);
/* now set the log levels and infile option, according to what we read */ /* now set the log levels and infile option, according to what we read */
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) { for (int i = 0; i < MAX_LOG_PREDEF_COMPONENTS; i++) {
g_log->log_component[i].level = map_str_to_int(log_level_names, *(logparams_level[i].strptr)); g_log->log_component[i].level = map_str_to_int(log_level_names, *logparams_level[i].strptr);
set_log(i, g_log->log_component[i].level); set_log(i, g_log->log_component[i].level);
if (*(logparams_logfile[i].uptr) == 1) if (*logparams_logfile[i].uptr == 1)
set_component_filelog(i); set_component_filelog(i);
} }
...@@ -386,16 +440,10 @@ void log_getconfig(log_t *g_log) ...@@ -386,16 +440,10 @@ void log_getconfig(log_t *g_log)
set_glog_onlinelog(consolelog); set_glog_onlinelog(consolelog);
} }
int register_log_component(char *name, int register_log_component(const char *name, const char *fext, int compidx)
char *fext,
int compidx)
{ {
int computed_compidx=compidx; int computed_compidx=compidx;
if (strlen(fext) > 3) {
fext[3]=0; /* limit log file extension to 3 chars */
}
if (compidx < 0) { /* this is not a pre-defined component */ if (compidx < 0) { /* this is not a pre-defined component */
for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) { for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) {
if (g_log->log_component[i].name == NULL) { if (g_log->log_component[i].name == NULL) {
...@@ -409,8 +457,9 @@ int register_log_component(char *name, ...@@ -409,8 +457,9 @@ int register_log_component(char *name,
g_log->log_component[computed_compidx].name = strdup(name); g_log->log_component[computed_compidx].name = strdup(name);
g_log->log_component[computed_compidx].stream = stdout; g_log->log_component[computed_compidx].stream = stdout;
g_log->log_component[computed_compidx].filelog = 0; g_log->log_component[computed_compidx].filelog = 0;
g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/<name>.%s */ g_log->log_rarely_used[computed_compidx].filelog_name = calloc(1, strlen(name) + 16); /* /tmp/<name>.%s */
sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext); sprintf(g_log->log_rarely_used[computed_compidx].filelog_name, "/tmp/%s.", name);
strncat(g_log->log_rarely_used[computed_compidx].filelog_name, fext, 3);
} else { } else {
fprintf(stderr,"{LOG} %s %d Couldn't register component %s\n",__FILE__,__LINE__,name); fprintf(stderr,"{LOG} %s %d Couldn't register component %s\n",__FILE__,__LINE__,name);
} }
...@@ -420,11 +469,13 @@ int register_log_component(char *name, ...@@ -420,11 +469,13 @@ int register_log_component(char *name,
static void unregister_all_log_components(void) static void unregister_all_log_components(void)
{ {
log_component_t* lc = &g_log->log_component[0]; log_component_t *lc = g_log->log_component;
log_component_back_t *lb = g_log->log_rarely_used;
while (lc->name) { while (lc->name) {
free((char *)lc->name); // defined as const, but assigned through strdup() free((char *)lc->name); // defined as const, but assigned through strdup()
free(lc->filelog_name); free(lb->filelog_name);
lc++; lc++;
lb++;
} }
} }
...@@ -441,7 +492,6 @@ int isLogInitDone (void) ...@@ -441,7 +492,6 @@ int isLogInitDone (void)
int logInit (void) int logInit (void)
{ {
int i;
g_log = calloc(1, sizeof(log_t)); g_log = calloc(1, sizeof(log_t));
if (g_log == NULL) { if (g_log == NULL) {
...@@ -449,69 +499,17 @@ int logInit (void) ...@@ -449,69 +499,17 @@ int logInit (void)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(g_log,0,sizeof(log_t)); for (int i = 0; i < MAX_LOG_PREDEF_COMPONENTS; i++)
register_log_component("PHY","log",PHY); register_log_component(comp_name[i], comp_extension[i], i);
register_log_component("MAC","log",MAC);
register_log_component("OPT","log",OPT);
register_log_component("RLC","log",RLC);
register_log_component("PDCP","log",PDCP);
register_log_component("RRC","log",RRC);
register_log_component("OMG","csv",OMG);
register_log_component("OTG","log",OTG);
register_log_component("OTG_LATENCY","dat",OTG_LATENCY);
register_log_component("OTG_LATENCY_BG","dat",OTG_LATENCY_BG);
register_log_component("OTG_GP","dat",OTG_GP);
register_log_component("OTG_GP_BG","dat",OTG_GP_BG);
register_log_component("OTG_JITTER","dat",OTG_JITTER);
register_log_component("PERF","",PERF);
register_log_component("OIP","",OIP);
register_log_component("OCM","log",OCM);
register_log_component("HW","",HW);
register_log_component("OSA","",OSA);
register_log_component("eRAL","",RAL_ENB);
register_log_component("mRAL","",RAL_UE);
register_log_component("ENB_APP","log",ENB_APP);
register_log_component("MCE_APP","log",MCE_APP);
register_log_component("MME_APP","log",MME_APP);
register_log_component("TMR","",TMR);
register_log_component("EMU","log",EMU);
register_log_component("USIM","txt",USIM);
register_log_component("SIM","txt",SIM);
/* following log component are used for the localization*/
register_log_component("LOCALIZE","log",LOCALIZE);
register_log_component("NAS","log",NAS);
register_log_component("UDP","",UDP_);
register_log_component("GTPU","",GTPU);
register_log_component("SDAP","",SDAP);
register_log_component("S1AP","",S1AP);
register_log_component("F1AP","",F1AP);
register_log_component("E1AP","",E1AP);
register_log_component("M2AP","",M2AP);
register_log_component("M3AP","",M3AP);
register_log_component("SCTP","",SCTP);
register_log_component("X2AP","",X2AP);
register_log_component("LOADER","log",LOADER);
register_log_component("ASN1","log",ASN1);
register_log_component("NFAPI_VNF","log",NFAPI_VNF);
register_log_component("NFAPI_PNF","log",NFAPI_PNF);
register_log_component("GNB_APP","log",GNB_APP);
register_log_component("NR_RRC","log",NR_RRC);
register_log_component("NR_MAC","log",NR_MAC);
register_log_component("NR_MAC_DCI", "log", NR_MAC_DCI);
register_log_component("NR_PHY_DCI", "log", NR_PHY_DCI);
register_log_component("NR_PHY","log",NR_PHY);
register_log_component("NGAP","",NGAP);
register_log_component("ITTI","log",ITTI);
register_log_component("UTIL","log",UTIL);
for (int i=0 ; log_level_names[i].name != NULL ; i++) for (int i=0 ; log_level_names[i].name != NULL ; i++)
g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name
g_log->filelog_name = "/tmp/openair.log"; g_log->filelog_name = "/tmp/openair.log";
log_getconfig(g_log); log_getconfig(g_log);
// set all unused component items to 0, they are for non predefined components // set all unused component items to 0, they are for non predefined components
for (i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { for (int i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); memset(&(g_log->log_component[i]),0,sizeof(log_component_t));
} }
...@@ -538,7 +536,7 @@ static inline int log_header(log_component_t *c, ...@@ -538,7 +536,7 @@ static inline int log_header(log_component_t *c,
int line, int line,
int level) int level)
{ {
int flag= g_log->flag | c->flag; int flag = g_log->flag;
char threadname[64]; char threadname[64];
if (flag & FLAG_THREAD ) { if (flag & FLAG_THREAD ) {
...@@ -628,8 +626,8 @@ void log_dump(int component, ...@@ -628,8 +626,8 @@ void log_dump(int component,
va_list args; va_list args;
char *wbuf; char *wbuf;
log_component_t *c = &g_log->log_component[component]; log_component_t *c = &g_log->log_component[component];
int flag= g_log->flag | c->flag; int flag = g_log->flag;
switch(datatype) { switch(datatype) {
case LOG_DUMP_DOUBLE: case LOG_DUMP_DOUBLE:
wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL); wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL);
...@@ -672,20 +670,17 @@ int set_log(int component, ...@@ -672,20 +670,17 @@ int set_log(int component,
int level) int level)
{ {
/* Checking parameters */ /* Checking parameters */
DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS), DevCheck((component >= 0) && (component < MAX_LOG_COMPONENTS), component, 0, MAX_LOG_COMPONENTS);
component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS);
DevCheck((level < NUM_LOG_LEVEL) && (level >= OAILOG_DISABLE), level, NUM_LOG_LEVEL, DevCheck((level < NUM_LOG_LEVEL) && (level >= OAILOG_DISABLE), level, NUM_LOG_LEVEL,
OAILOG_ERR); OAILOG_ERR);
if ( g_log->log_component[component].level != OAILOG_DISABLE ) if ( g_log->log_component[component].level != OAILOG_DISABLE )
g_log->log_component[component].savedlevel = g_log->log_component[component].level; g_log->log_rarely_used[component].savedlevel = g_log->log_component[component].level;
g_log->log_component[component].level = level; g_log->log_component[component].level = level;
return 0; return 0;
} }
void set_glog(int level) void set_glog(int level)
{ {
for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) {
...@@ -697,7 +692,7 @@ void set_glog_onlinelog(int enable) ...@@ -697,7 +692,7 @@ void set_glog_onlinelog(int enable)
{ {
for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) {
if ( enable ) { if ( enable ) {
g_log->log_component[c].level = g_log->log_component[c].savedlevel; g_log->log_component[c].level = g_log->log_rarely_used[c].savedlevel;
g_log->log_component[c].vprint = vfprintf; g_log->log_component[c].vprint = vfprintf;
g_log->log_component[c].print = fprintf; g_log->log_component[c].print = fprintf;
g_log->log_component[c].stream = stdout; g_log->log_component[c].stream = stdout;
...@@ -706,6 +701,7 @@ void set_glog_onlinelog(int enable) ...@@ -706,6 +701,7 @@ void set_glog_onlinelog(int enable)
} }
} }
} }
void set_glog_filelog(int enable) void set_glog_filelog(int enable)
{ {
static FILE *fptr; static FILE *fptr;
...@@ -734,13 +730,14 @@ void set_glog_filelog(int enable) ...@@ -734,13 +730,14 @@ void set_glog_filelog(int enable)
void set_component_filelog(int comp) void set_component_filelog(int comp)
{ {
if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) { if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) {
g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w"); g_log->log_component[comp].stream = fopen(g_log->log_rarely_used[comp].filelog_name, "w");
} }
g_log->log_component[comp].vprint = vfprintf; g_log->log_component[comp].vprint = vfprintf;
g_log->log_component[comp].print = fprintf; g_log->log_component[comp].print = fprintf;
g_log->log_component[comp].filelog = 1; g_log->log_component[comp].filelog = 1;
} }
void close_component_filelog(int comp) void close_component_filelog(int comp)
{ {
g_log->log_component[comp].filelog = 0; g_log->log_component[comp].filelog = 0;
...@@ -777,40 +774,19 @@ int map_str_to_int(const mapping *map, const char *str) ...@@ -777,40 +774,19 @@ int map_str_to_int(const mapping *map, const char *str)
/* map an int to a string. Takes a mapping array and a value */ /* map an int to a string. Takes a mapping array and a value */
char *map_int_to_str(const mapping *map, const int val) char *map_int_to_str(const mapping *map, const int val)
{ {
while (1) { while (map->name) {
if (map->name == NULL) {
return NULL;
}
if (map->value == val) { if (map->value == val) {
return map->name; return map->name;
} }
map++; map++;
} }
} return NULL;
int is_newline(char *str,
int size)
{
int i;
for ( i = 0; i < size; i++ ) {
if ( str[i] == '\n' ) {
return 1;
}
}
/* if we get all the way to here, there must not have been a newline! */
return 0;
} }
void logClean (void) void logClean (void)
{ {
int i;
if(isLogInitDone()) { if(isLogInitDone()) {
for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { for (int i = 0; i < MAX_LOG_COMPONENTS; i++) {
close_component_filelog(i); close_component_filelog(i);
} }
} }
...@@ -885,7 +861,7 @@ static void log_output_memory(log_component_t *c, const char *file, const char * ...@@ -885,7 +861,7 @@ static void log_output_memory(log_component_t *c, const char *file, const char *
len = MAX_LOG_TOTAL; len = MAX_LOG_TOTAL;
} }
} }
if ( !((g_log->flag | c->flag) & FLAG_NOCOLOR) ) { if (!((g_log->flag) & FLAG_NOCOLOR)) {
int n = snprintf(log_buffer+len, MAX_LOG_TOTAL-len, "%s", log_level_highlight_end[level]); int n = snprintf(log_buffer+len, MAX_LOG_TOTAL-len, "%s", log_level_highlight_end[level]);
if (n > 0) { if (n > 0) {
len += n; len += n;
...@@ -935,28 +911,22 @@ static void log_output_memory(log_component_t *c, const char *file, const char * ...@@ -935,28 +911,22 @@ static void log_output_memory(log_component_t *c, const char *file, const char *
} }
} }
int logInit_log_mem (void) int logInit_log_mem (char * filename)
{ {
if (log_mem_flag == 1) { log_mem_flag = 1;
log_mem_d[0].buf_p = malloc(LOG_MEM_SIZE); log_mem_filename = filename; // in present code, the parameter is safe permanent pointer
log_mem_d[0].buf_index = 0; for (log_mem_cnt_t *ptr = log_mem_d; ptr < log_mem_d + sizeofArray(log_mem_d); ptr++)
log_mem_d[0].enable_flag = 1; *ptr = (log_mem_cnt_t){
log_mem_d[1].buf_p = malloc(LOG_MEM_SIZE); .buf_p = malloc(LOG_MEM_SIZE),
log_mem_d[1].buf_index = 0; .buf_index = 0,
log_mem_d[1].enable_flag = 1; .enable_flag = 1,
log_mem_side = 0; };
if ((pthread_mutex_init(&log_mem_lock, NULL) != 0) || (pthread_cond_init(&log_mem_notify, NULL) != 0)) { log_mem_side = 0;
log_mem_d[1].enable_flag=0; if ((pthread_mutex_init(&log_mem_lock, NULL) != 0) || (pthread_cond_init(&log_mem_notify, NULL) != 0)) {
return -1; log_mem_d[1].enable_flag=0;
} return -1;
pthread_create(&log_mem_thread, NULL, (void *(*)(void *))flush_mem_to_file, (void *)NULL);
} else {
log_mem_d[0].buf_p = NULL;
log_mem_d[1].buf_p = NULL;
log_mem_d[0].enable_flag = 0;
log_mem_d[1].enable_flag = 0;
} }
pthread_create(&log_mem_thread, NULL, (void *(*)(void *))flush_mem_to_file, (void *)NULL);
printf("log init done\n"); printf("log init done\n");
return 0; return 0;
......
...@@ -57,8 +57,6 @@ ...@@ -57,8 +57,6 @@
#ifdef NDEBUG #ifdef NDEBUG
#warning assert is disabled #warning assert is disabled
#endif #endif
#define NUM_ELEMENTS(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
#define CHECK_INDEX(ARRAY, INDEX) assert((INDEX) < NUM_ELEMENTS(ARRAY))
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -87,31 +85,6 @@ extern "C" { ...@@ -87,31 +85,6 @@ extern "C" {
#define NUM_LOG_LEVEL 6 /*!< \brief the number of message levels users have with LOG (OAILOG_DISABLE is not available to user as a level, so it is not included)*/ #define NUM_LOG_LEVEL 6 /*!< \brief the number of message levels users have with LOG (OAILOG_DISABLE is not available to user as a level, so it is not included)*/
/** @}*/ /** @}*/
/** @defgroup _log_format Defined log format
* @ingroup _macro
* @brief Macro of log formats defined by LOG
* @{*/
/* .log_format = 0x13 uncolored standard messages
* .log_format = 0x93 colored standard messages */
/* keep white space in first position; switching it to 0 allows colors to be disabled*/
#define LOG_RED "\033[1;31m" /*!< \brief VT100 sequence for bold red foreground */
#define LOG_GREEN "\033[32m" /*!< \brief VT100 sequence for green foreground */
#define LOG_ORANGE "\033[93m" /*!< \brief VT100 sequence for orange foreground */
#define LOG_BLUE "\033[34m" /*!< \brief VT100 sequence for blue foreground */
#define LOG_CYBL "\033[40;36m" /*!< \brief VT100 sequence for cyan foreground on black background */
#define LOG_RESET "\033[0m" /*!< \brief VT100 sequence for reset (black) foreground */
#define FLAG_NOCOLOR 0x0001 /*!< \brief use colors in log messages, depending on level */
#define FLAG_THREAD 0x0008 /*!< \brief display thread name in log messages */
#define FLAG_LEVEL 0x0010 /*!< \brief display log level in log messages */
#define FLAG_FUNCT 0x0020
#define FLAG_FILE_LINE 0x0040
#define FLAG_TIME 0x0100
#define FLAG_THREAD_ID 0x0200
#define FLAG_REAL_TIME 0x0400
#define FLAG_INITIALIZED 0x8000
/** @}*/
#define SET_LOG_OPTION(O) g_log->flag = (g_log->flag | O) #define SET_LOG_OPTION(O) g_log->flag = (g_log->flag | O)
#define CLEAR_LOG_OPTION(O) g_log->flag = (g_log->flag & (~O)) #define CLEAR_LOG_OPTION(O) g_log->flag = (g_log->flag & (~O))
...@@ -140,92 +113,73 @@ extern "C" { ...@@ -140,92 +113,73 @@ extern "C" {
#define DEBUG_DLSCH_DECOD (1<<14) #define DEBUG_DLSCH_DECOD (1<<14)
#define UE_TIMING (1<<20) #define UE_TIMING (1<<20)
#define LOG_MASKMAP_INIT {\
{"PRACH", DEBUG_PRACH},\
{"RU", DEBUG_RU},\
{"UE_PHYPROC", DEBUG_UE_PHYPROC},\
{"LTEESTIM", DEBUG_LTEESTIM},\
{"DLCELLSPEC", DEBUG_DLCELLSPEC},\
{"ULSCH", DEBUG_ULSCH},\
{"RRC", DEBUG_RRC},\
{"PDCP", DEBUG_PDCP},\
{"DFT", DEBUG_DFT},\
{"ASN1", DEBUG_ASN1},\
{"CTRLSOCKET", DEBUG_CTRLSOCKET},\
{"SECURITY", DEBUG_SECURITY},\
{"NAS", DEBUG_NAS},\
{"RLC", DEBUG_RLC},\
{"DLSCH_DECOD", DEBUG_DLSCH_DECOD},\
{"UE_TIMING", UE_TIMING},\
{NULL,-1}\
}
#define SET_LOG_DEBUG(B) g_log->debug_mask = (g_log->debug_mask | B) #define SET_LOG_DEBUG(B) g_log->debug_mask = (g_log->debug_mask | B)
#define CLEAR_LOG_DEBUG(B) g_log->debug_mask = (g_log->debug_mask & (~B)) #define CLEAR_LOG_DEBUG(B) g_log->debug_mask = (g_log->debug_mask & (~B))
#define SET_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask | B) #define SET_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask | B)
#define CLEAR_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask & (~B)) #define CLEAR_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask & (~B))
typedef enum { #define FOREACH_COMP(COMP_DEF) \
MIN_LOG_COMPONENTS = 0, COMP_DEF(PHY, log) \
PHY = MIN_LOG_COMPONENTS, COMP_DEF(MAC, log) \
MAC, COMP_DEF(EMU, log) \
EMU, COMP_DEF(SIM, txt) \
SIM, COMP_DEF(OMG, csv) \
OMG, COMP_DEF(OPT, log) \
OPT, COMP_DEF(OTG, log) \
OTG, COMP_DEF(OTG_LATENCY, dat) \
OTG_LATENCY, COMP_DEF(OTG_LATENCY_BG, dat) \
OTG_LATENCY_BG, COMP_DEF(OTG_GP, dat) \
OTG_GP, COMP_DEF(OTG_GP_BG, dat) \
OTG_GP_BG, COMP_DEF(OTG_JITTER, dat) \
OTG_JITTER, COMP_DEF(RLC, ) \
RLC, COMP_DEF(PDCP, ) \
PDCP, COMP_DEF(RRC, ) \
RRC, COMP_DEF(NAS, log) \
NAS, COMP_DEF(OIP, ) \
PERF, COMP_DEF(CLI, ) \
OIP, COMP_DEF(OCM, ) \
CLI, COMP_DEF(GTPU, ) \
OCM, COMP_DEF(SDAP, ) \
UDP_, COMP_DEF(SPGW, ) \
GTPU, COMP_DEF(S1AP, ) \
SDAP, COMP_DEF(F1AP, ) \
SPGW, COMP_DEF(E1AP, ) \
S1AP, COMP_DEF(SCTP, ) \
F1AP, COMP_DEF(HW, ) \
E1AP, COMP_DEF(OSA, ) \
SCTP, COMP_DEF(ENB_APP, log) \
HW, COMP_DEF(MCE_APP, log) \
OSA, COMP_DEF(MME_APP, log) \
RAL_ENB, COMP_DEF(TMR, ) \
RAL_UE, COMP_DEF(USIM, log) \
ENB_APP, COMP_DEF(F1U, ) \
MCE_APP, COMP_DEF(X2AP, ) \
MME_APP, COMP_DEF(M2AP, ) \
TMR, COMP_DEF(M3AP, ) \
USIM, COMP_DEF(NGAP, ) \
LOCALIZE, COMP_DEF(GNB_APP, log) \
F1U, COMP_DEF(NR_RRC, log) \
X2AP, COMP_DEF(NR_MAC, log) \
M2AP, COMP_DEF(NR_MAC_DCI, log) \
M3AP, COMP_DEF(NR_PHY_DCI, log) \
NGAP, COMP_DEF(NR_PHY, log) \
GNB_APP, COMP_DEF(LOADER, log) \
NR_RRC, COMP_DEF(ASN1, log) \
NR_MAC, COMP_DEF(NFAPI_VNF, log) \
NR_MAC_DCI, COMP_DEF(NFAPI_PNF, log) \
NR_PHY_DCI, COMP_DEF(ITTI, log) \
NR_PHY, COMP_DEF(UTIL, log) \
LOADER, COMP_DEF(MAX_LOG_PREDEF_COMPONENTS, )
ASN1,
NFAPI_VNF, #define COMP_ENUM(comp, file_extension) comp,
NFAPI_PNF, typedef enum { FOREACH_COMP(COMP_ENUM) } comp_name_t;
ITTI,
UTIL, #define COMP_TEXT(comp, file_extension) #comp,
MAX_LOG_PREDEF_COMPONENTS, static const char *const comp_name[] = {FOREACH_COMP(COMP_TEXT)};
} comp_name_t;
#define COMP_EXTENSION(comp, file_extension) #file_extension,
static const char *const comp_extension[] = {FOREACH_COMP(COMP_EXTENSION)};
#define MAX_LOG_DYNALLOC_COMPONENTS 20 #define MAX_LOG_DYNALLOC_COMPONENTS 20
#define MAX_LOG_COMPONENTS (MAX_LOG_PREDEF_COMPONENTS + MAX_LOG_DYNALLOC_COMPONENTS) #define MAX_LOG_COMPONENTS (MAX_LOG_PREDEF_COMPONENTS + MAX_LOG_DYNALLOC_COMPONENTS)
...@@ -237,23 +191,24 @@ typedef struct { ...@@ -237,23 +191,24 @@ typedef struct {
typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap ); typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap );
typedef int(*log_print_func_t)(FILE *stream, const char *format, ... ); typedef int(*log_print_func_t)(FILE *stream, const char *format, ... );
typedef struct {
int savedlevel;
char *filelog_name;
} log_component_back_t;
typedef struct { typedef struct {
const char *name; const char *name;
int level; int level;
int savedlevel; int filelog;
int flag;
int filelog;
char *filelog_name;
FILE *stream; FILE *stream;
log_vprint_func_t vprint; log_vprint_func_t vprint;
log_print_func_t print; log_print_func_t print;
/* SR: make the log buffer component relative */
// char log_buffer[MAX_LOG_TOTAL];
} log_component_t; } log_component_t;
typedef struct { typedef struct {
log_component_t log_component[MAX_LOG_COMPONENTS]; log_component_t log_component[MAX_LOG_COMPONENTS];
log_component_back_t log_rarely_used[MAX_LOG_COMPONENTS];
char level2string[NUM_LOG_LEVEL]; char level2string[NUM_LOG_LEVEL];
int flag; int flag;
char *filelog_name; char *filelog_name;
...@@ -272,8 +227,7 @@ extern "C" { ...@@ -272,8 +227,7 @@ extern "C" {
} }
#endif #endif
#endif #endif
/*--- INCLUDES ---------------------------------------------------------------*/
# include "log_if.h"
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
int logInit (void); int logInit (void);
void logTerm (void); void logTerm (void);
...@@ -284,6 +238,9 @@ void log_dump(int component, void *buffer, int buffsize,int datatype, const char ...@@ -284,6 +238,9 @@ void log_dump(int component, void *buffer, int buffsize,int datatype, const char
int set_log(int component, int level); int set_log(int component, int level);
void set_glog(int level); void set_glog(int level);
mapping * log_level_names_ptr(void);
mapping * log_option_names_ptr(void);
mapping * log_maskmap_ptr(void);
void set_glog_onlinelog(int enable); void set_glog_onlinelog(int enable);
void set_glog_filelog(int enable); void set_glog_filelog(int enable);
void set_component_filelog(int comp); void set_component_filelog(int comp);
...@@ -292,21 +249,11 @@ void set_component_consolelog(int comp); ...@@ -292,21 +249,11 @@ void set_component_consolelog(int comp);
int map_str_to_int(const mapping *map, const char *str); int map_str_to_int(const mapping *map, const char *str);
char *map_int_to_str(const mapping *map, const int val); char *map_int_to_str(const mapping *map, const int val);
void logClean (void); void logClean (void);
int is_newline( char *str, int size);
int register_log_component(char *name, char *fext, int compidx); int register_log_component(const char *name, const char *fext, int compidx);
#define LOG_MEM_SIZE 100*1024*1024 int logInit_log_mem(char*);
#define LOG_MEM_FILE "./logmem.log"
void flush_mem_to_file(void);
int logInit_log_mem(void);
void close_log_mem(void); void close_log_mem(void);
typedef struct {
char* buf_p;
int buf_index;
int enable_flag;
} log_mem_cnt_t;
/** @}*/ /** @}*/
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "log.h"
extern log_t *g_log;
extern const mapping log_level_names[];
extern const mapping log_options[];
extern const mapping log_maskmap[];
extern int log_mem_flag;
extern char * log_mem_filename;
extern char logmem_filename[1024];
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file log_if.h
* \brief log interface
* \author Navid Nikaein
* \date 2009 - 2014
* \version 0.3
* \warning This component can be runned only in user-space
* @ingroup routing
*/
// LTS: kept this file for compatibility
// this file was probably a trial to separate internal functions and external ones
// but it has never been finished, most source code include directly log.h (not log_if.h)
#include "log.h"
...@@ -256,6 +256,9 @@ void print_threads(char *buf, int debug, telnet_printfunc_t prnt) ...@@ -256,6 +256,9 @@ void print_threads(char *buf, int debug, telnet_printfunc_t prnt)
int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfunc_t prnt) int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfunc_t prnt)
{ {
webdatadef_t *logsdata = (webdatadef_t *)data; webdatadef_t *logsdata = (webdatadef_t *)data;
const mapping *const log_level_names = log_level_names_ptr();
const mapping *const log_options = log_option_names_ptr();
const mapping *log_maskmap = log_maskmap_ptr();
if (strncmp(cmdbuff, "set", 3) == 0) { if (strncmp(cmdbuff, "set", 3) == 0) {
telnet_printfunc_t printfunc = (prnt != NULL) ? prnt : (telnet_printfunc_t)printf; telnet_printfunc_t printfunc = (prnt != NULL) ? prnt : (telnet_printfunc_t)printf;
if (strcasestr(cmdbuff, "loglvl") != NULL) { if (strcasestr(cmdbuff, "loglvl") != NULL) {
...@@ -274,7 +277,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun ...@@ -274,7 +277,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun
logsdata->lines[0].val[0], logsdata->lines[0].val[0],
logsdata->lines[0].val[1], logsdata->lines[0].val[1],
enabled ? "enabled" : "disabled", enabled ? "enabled" : "disabled",
loginfile ? g_log->log_component[logsdata->numlines].filelog_name : "stdout"); loginfile ? g_log->log_rarely_used[logsdata->numlines].filelog_name : "stdout");
} }
if (strcasestr(cmdbuff, "logopt") != NULL) { if (strcasestr(cmdbuff, "logopt") != NULL) {
int optbit = map_str_to_int(log_options, logsdata->lines[0].val[0]); int optbit = map_str_to_int(log_options, logsdata->lines[0].val[0]);
...@@ -329,12 +332,14 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun ...@@ -329,12 +332,14 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun
snprintf(logsdata->columns[3].coltitle, TELNET_CMD_MAXSIZE, "in file"); snprintf(logsdata->columns[3].coltitle, TELNET_CMD_MAXSIZE, "in file");
logsdata->columns[3].coltype = TELNET_CHECKVAL_BOOL; logsdata->columns[3].coltype = TELNET_CHECKVAL_BOOL;
for (int i = MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { for (int i = 0; i < MAX_LOG_COMPONENTS; i++) {
if (g_log->log_component[i].name != NULL) { if (g_log->log_component[i].name != NULL) {
logsdata->numlines++; logsdata->numlines++;
logsdata->lines[i].val[0] = (char *)(g_log->log_component[i].name); logsdata->lines[i].val[0] = (char *)(g_log->log_component[i].name);
logsdata->lines[i].val[1] = map_int_to_str(log_level_names, (g_log->log_component[i].level >= 0) ? g_log->log_component[i].level : g_log->log_component[i].savedlevel); logsdata->lines[i].val[1] = map_int_to_str(
log_level_names,
(g_log->log_component[i].level >= 0) ? g_log->log_component[i].level : g_log->log_rarely_used[i].savedlevel);
logsdata->lines[i].val[2] = (g_log->log_component[i].level >= 0) ? "true" : "false"; logsdata->lines[i].val[2] = (g_log->log_component[i].level >= 0) ? "true" : "false";
logsdata->lines[i].val[3] = (g_log->log_component[i].filelog > 0) ? "true" : "false"; logsdata->lines[i].val[3] = (g_log->log_component[i].filelog > 0) ? "true" : "false";
} }
...@@ -353,7 +358,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun ...@@ -353,7 +358,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun
for (int i = 0; log_maskmap[i].name != NULL; i++) { for (int i = 0; log_maskmap[i].name != NULL; i++) {
logsdata->numlines++; logsdata->numlines++;
logsdata->lines[i].val[0] = log_maskmap[i].name; logsdata->lines[i].val[0] = (char *)log_maskmap[i].name;
logsdata->lines[i].val[1] = (g_log->debug_mask & log_maskmap[i].value) ? "true" : "false"; logsdata->lines[i].val[1] = (g_log->debug_mask & log_maskmap[i].value) ? "true" : "false";
logsdata->lines[i].val[2] = (g_log->dump_mask & log_maskmap[i].value) ? "true" : "false"; logsdata->lines[i].val[2] = (g_log->dump_mask & log_maskmap[i].value) ? "true" : "false";
} }
...@@ -370,7 +375,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun ...@@ -370,7 +375,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun
for (int i = 0; log_options[i].name != NULL; i++) { for (int i = 0; log_options[i].name != NULL; i++) {
logsdata->numlines++; logsdata->numlines++;
logsdata->lines[i].val[0] = log_options[i].name; logsdata->lines[i].val[0] = (char *)log_options[i].name;
logsdata->lines[i].val[1] = (g_log->flag & log_options[i].value) ? "true" : "false"; logsdata->lines[i].val[1] = (g_log->flag & log_options[i].value) ? "true" : "false";
} }
} }
...@@ -395,17 +400,23 @@ int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt) ...@@ -395,17 +400,23 @@ int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt)
} }
if (strcasestr(buf,"loglvl") != NULL) { if (strcasestr(buf,"loglvl") != NULL) {
prnt("\n component level enabled output\n"); prnt("\n component level enabled output\n");
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { const mapping *const log_level_names = log_level_names_ptr();
if (g_log->log_component[i].name != NULL) { for (int i = 0; i < MAX_LOG_COMPONENTS; i++) {
prnt("%02i %17.17s:%10.10s %s %s\n",i ,g_log->log_component[i].name, if (g_log->log_component[i].name != NULL) {
map_int_to_str(log_level_names,(g_log->log_component[i].level>=0)?g_log->log_component[i].level:g_log->log_component[i].savedlevel), prnt("%02i %17.17s:%10.10s %s %s\n",
((g_log->log_component[i].level>=0)?"Y":"N"), i,
((g_log->log_component[i].filelog>0)?g_log->log_component[i].filelog_name:"stdout")); g_log->log_component[i].name,
} map_int_to_str(
log_level_names,
(g_log->log_component[i].level >= 0) ? g_log->log_component[i].level : g_log->log_rarely_used[i].savedlevel),
((g_log->log_component[i].level >= 0) ? "Y" : "N"),
((g_log->log_component[i].filelog > 0) ? g_log->log_rarely_used[i].filelog_name : "stdout"));
}
} }
} }
if (strcasestr(buf,"logopt") != NULL) { if (strcasestr(buf,"logopt") != NULL) {
prnt("\n option enabled\n"); prnt("\n option enabled\n");
const mapping *const log_options = log_option_names_ptr();
for (int i=0; log_options[i].name != NULL; i++) { for (int i=0; log_options[i].name != NULL; i++) {
prnt("%02i %17.17s %10.10s \n",i ,log_options[i].name, prnt("%02i %17.17s %10.10s \n",i ,log_options[i].name,
((g_log->flag & log_options[i].value)?"Y":"N") ); ((g_log->flag & log_options[i].value)?"Y":"N") );
...@@ -413,6 +424,7 @@ int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt) ...@@ -413,6 +424,7 @@ int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt)
} }
if (strcasestr(buf,"dbgopt") != NULL) { if (strcasestr(buf,"dbgopt") != NULL) {
prnt("\n module debug dumpfile\n"); prnt("\n module debug dumpfile\n");
const mapping *log_maskmap = log_maskmap_ptr();
for (int i=0; log_maskmap[i].name != NULL ; i++) { for (int i=0; log_maskmap[i].name != NULL ; i++) {
prnt("%02i %17.17s %5.5s %5.5s\n",i ,log_maskmap[i].name, prnt("%02i %17.17s %5.5s %5.5s\n",i ,log_maskmap[i].name,
((g_log->debug_mask & log_maskmap[i].value)?"Y":"N"), ((g_log->debug_mask & log_maskmap[i].value)?"Y":"N"),
...@@ -528,7 +540,9 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2); ...@@ -528,7 +540,9 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2);
if (debug > 0) if (debug > 0)
prnt( "proccmd_log received %s\n s=%i sub command %s\n",buf,s,((logsubcmd==NULL)?"":logsubcmd)); prnt( "proccmd_log received %s\n s=%i sub command %s\n",buf,s,((logsubcmd==NULL)?"":logsubcmd));
const mapping *const log_level_names = log_level_names_ptr();
const mapping *const log_options = log_option_names_ptr();
const mapping *log_maskmap = log_maskmap_ptr();
if (s == 1 && logsubcmd != NULL) { if (s == 1 && logsubcmd != NULL) {
if (strcasestr(logsubcmd,"online") != NULL) { if (strcasestr(logsubcmd,"online") != NULL) {
if (strcasestr(buf,"noonline") != NULL) { if (strcasestr(buf,"noonline") != NULL) {
...@@ -540,21 +554,21 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2); ...@@ -540,21 +554,21 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2);
} }
} }
else if (strcasestr(logsubcmd,"show") != NULL) { else if (strcasestr(logsubcmd,"show") != NULL) {
prnt("Available log levels: \n "); prnt("Available log levels: \n ");
for (int i=0; log_level_names[i].name != NULL; i++) for (int i = 0; log_level_names[i].name != NULL; i++)
prnt("%s ",log_level_names[i].name); prnt("%s ", log_level_names[i].name);
prnt("\n\n"); prnt("\n\n");
prnt("Available display options: \n "); prnt("Available display options: \n ");
for (int i=0; log_options[i].name != NULL; i++) for (int i = 0; log_options[i].name != NULL; i++)
prnt("%s ",log_options[i].name); prnt("%s ", log_options[i].name);
prnt("\n\n"); prnt("\n\n");
prnt("Available debug and dump options: \n "); prnt("Available debug and dump options: \n ");
for (int i=0; log_maskmap[i].name != NULL; i++) for (int i = 0; log_maskmap[i].name != NULL; i++)
prnt("%s ",log_maskmap[i].name); prnt("%s ", log_maskmap[i].name);
prnt("\n\n"); prnt("\n\n");
proccmd_show("loglvl",debug,prnt); proccmd_show("loglvl", debug, prnt);
proccmd_show("logopt",debug,prnt); proccmd_show("logopt", debug, prnt);
proccmd_show("dbgopt",debug,prnt); proccmd_show("dbgopt", debug, prnt);
} }
else if (strcasestr(logsubcmd,"help") != NULL) { else if (strcasestr(logsubcmd,"help") != NULL) {
prnt(PROCCMD_LOG_HELP_STRING); prnt(PROCCMD_LOG_HELP_STRING);
...@@ -569,40 +583,40 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2); ...@@ -569,40 +583,40 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2);
l=sscanf(logsubcmd,"%m[^'_']_%ms",&logparam,&opt); l=sscanf(logsubcmd,"%m[^'_']_%ms",&logparam,&opt);
if (l == 2 && strcmp(logparam,"print") == 0){ if (l == 2 && strcmp(logparam,"print") == 0){
optbit=map_str_to_int(log_options,opt); optbit = map_str_to_int(log_options, opt);
if (optbit < 0) { if (optbit < 0) {
prnt("option %s unknown\n",opt); prnt("option %s unknown\n", opt);
} else { } else {
if (idx1 > 0) if (idx1 > 0)
SET_LOG_OPTION(optbit); SET_LOG_OPTION(optbit);
else else
CLEAR_LOG_OPTION(optbit); CLEAR_LOG_OPTION(optbit);
proccmd_show("logopt",debug,prnt); proccmd_show("logopt", debug, prnt);
} }
} }
else if (l == 2 && strcmp(logparam,"debug") == 0){ else if (l == 2 && strcmp(logparam,"debug") == 0){
optbit=map_str_to_int(log_maskmap,opt); optbit = map_str_to_int(log_maskmap, opt);
if (optbit < 0) { if (optbit < 0) {
prnt("module %s unknown\n",opt); prnt("module %s unknown\n", opt);
} else { } else {
if (idx1 > 0) if (idx1 > 0)
SET_LOG_DEBUG(optbit); SET_LOG_DEBUG(optbit);
else else
CLEAR_LOG_DEBUG(optbit); CLEAR_LOG_DEBUG(optbit);
proccmd_show("dbgopt",debug,prnt); proccmd_show("dbgopt", debug, prnt);
} }
} }
else if (l == 2 && strcmp(logparam,"dump") == 0){ else if (l == 2 && strcmp(logparam,"dump") == 0){
optbit=map_str_to_int(log_maskmap,opt); optbit = map_str_to_int(log_maskmap, opt);
if (optbit < 0) { if (optbit < 0) {
prnt("module %s unknown\n",opt); prnt("module %s unknown\n", opt);
} else { } else {
if (idx1 > 0) if (idx1 > 0)
SET_LOG_DUMP(optbit); SET_LOG_DUMP(optbit);
else else
CLEAR_LOG_DUMP(optbit); CLEAR_LOG_DUMP(optbit);
proccmd_show("dump", debug, prnt); proccmd_show("dump", debug, prnt);
} }
} }
if (logparam != NULL) free(logparam); if (logparam != NULL) free(logparam);
if (opt != NULL) free(opt); if (opt != NULL) free(opt);
...@@ -620,11 +634,11 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2); ...@@ -620,11 +634,11 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2);
prnt("l=%i, %s %s\n",l,((logparam==NULL)?"\"\"":logparam), ((tmpstr==NULL)?"\"\"":tmpstr)); prnt("l=%i, %s %s\n",l,((logparam==NULL)?"\"\"":logparam), ((tmpstr==NULL)?"\"\"":tmpstr));
if (l ==2 ) { if (l ==2 ) {
if (strcmp(logparam,"level") == 0) { if (strcmp(logparam,"level") == 0) {
level=map_str_to_int(log_level_names,tmpstr); level = map_str_to_int(log_level_names, tmpstr);
if (level < 0) { if (level < 0) {
prnt("level %s unknown\n",tmpstr); prnt("level %s unknown\n", tmpstr);
level=OAILOG_DISABLE - 1; level = OAILOG_DISABLE - 1;
} }
} else { } else {
prnt("%s%s unknown log sub command \n",logparam, tmpstr); prnt("%s%s unknown log sub command \n",logparam, tmpstr);
} }
...@@ -650,7 +664,7 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2); ...@@ -650,7 +664,7 @@ int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2);
if (level >= OAILOG_DISABLE) if (level >= OAILOG_DISABLE)
set_log(i, level); set_log(i, level);
else if ( enable == 1) else if ( enable == 1)
set_log(i,g_log->log_component[i].savedlevel); set_log(i, g_log->log_rarely_used[i].savedlevel);
else if ( filelog == 1 ) { else if ( filelog == 1 ) {
set_component_filelog(i); set_component_filelog(i);
} else if ( filelog == 0 ) { } else if ( filelog == 0 ) {
......
...@@ -18,6 +18,7 @@ extern "C" { ...@@ -18,6 +18,7 @@ extern "C" {
#endif #endif
#define sizeofArray(a) (sizeof(a)/sizeof(*(a))) #define sizeofArray(a) (sizeof(a)/sizeof(*(a)))
#define CHECK_INDEX(ARRAY, INDEX) assert((INDEX) < sizeofArray(ARRAY))
// Prevent double evaluation in max macro // Prevent double evaluation in max macro
#define cmax(a,b) ({ __typeof__ (a) _a = (a); \ #define cmax(a,b) ({ __typeof__ (a) _a = (a); \
......
...@@ -902,7 +902,6 @@ INPUT = \ ...@@ -902,7 +902,6 @@ INPUT = \
@CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/vcd_signal_dumper.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/vcd_signal_dumper.h \
@CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/log.c \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/log.c \
@CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/log.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/log.h \
@CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/log_extern.h \
@CMAKE_CURRENT_SOURCE_DIR@/../common/utils/time_stat.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/time_stat.h \
@CMAKE_CURRENT_SOURCE_DIR@/../common/utils/ocp_itti/all_msg.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/ocp_itti/all_msg.h \
@CMAKE_CURRENT_SOURCE_DIR@/../common/utils/ocp_itti/intertask_interface.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/ocp_itti/intertask_interface.h \
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
#include "common/ran_context.h" #include "common/ran_context.h"
#include "RRC/LTE/rrc_extern.h" #include "RRC/LTE/rrc_extern.h"
#include "PHY_INTERFACE/phy_interface.h" #include "PHY_INTERFACE/phy_interface.h"
#include "common/utils/LOG/log_extern.h" #include "common/utils/LOG/log.h"
#include "UTIL/OTG/otg_tx.h" #include "UTIL/OTG/otg_tx.h"
#include "UTIL/OTG/otg_externs.h" #include "UTIL/OTG/otg_externs.h"
#include "UTIL/MATH/oml.h" #include "UTIL/MATH/oml.h"
......
...@@ -138,10 +138,8 @@ void get_common_options(configmodule_interface_t *cfg, uint32_t execmask) ...@@ -138,10 +138,8 @@ void get_common_options(configmodule_interface_t *cfg, uint32_t execmask)
} }
if (logmem_filename != NULL && strlen(logmem_filename) > 0) { if (logmem_filename != NULL && strlen(logmem_filename) > 0) {
log_mem_filename = &logmem_filename[0]; printf("Enabling OPT for log save at memory %s\n",logmem_filename);
log_mem_flag = 1; logInit_log_mem(logmem_filename);
printf("Enabling OPT for log save at memory %s\n",log_mem_filename);
logInit_log_mem();
} }
if (noS1) { if (noS1) {
......
...@@ -953,7 +953,7 @@ typedef enum {no_relay=1,unicast_relay_type1,unicast_relay_type2, multicast_rela ...@@ -953,7 +953,7 @@ typedef enum {no_relay=1,unicast_relay_type1,unicast_relay_type2, multicast_rela
#define NB_BANDS_MAX 8 #define NB_BANDS_MAX 8
#include "common/utils/LOG/log_extern.h" #include "common/utils/LOG/log.h"
extern pthread_cond_t sync_cond; extern pthread_cond_t sync_cond;
extern pthread_mutex_t sync_mutex; extern pthread_mutex_t sync_mutex;
extern int sync_var; extern int sync_var;
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include "LAYER2/MAC/defs.h" #include "LAYER2/MAC/defs.h"
#include "PHY_INTERFACE/defs.h" #include "PHY_INTERFACE/defs.h"
#include "LAYER2/MAC/vars.h" #include "LAYER2/MAC/vars.h"
#include "UTIL/LOG/log_extern.h" #include "UTIL/LOG/log.h"
uint16_t n_rnti = 0x1235; uint16_t n_rnti = 0x1235;
int n_users = 1; int n_users = 1;
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "SCHED/vars.h" #include "SCHED/vars.h"
#include "LAYER2/MAC/vars.h" #include "LAYER2/MAC/vars.h"
#include "UTIL/LOG/log_extern.h" #include "UTIL/LOG/log.h"
#include "unitary_defs.h" #include "unitary_defs.h"
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include "common/utils/LOG/log.h" #include "common/utils/LOG/log.h"
#include "common/utils/nr/nr_common.h" #include "common/utils/nr/nr_common.h"
#include "common/utils/LOG/log_extern.h"
#include "assertions.h" #include "assertions.h"
#include "common/utils/ocp_itti/intertask_interface.h" #include "common/utils/ocp_itti/intertask_interface.h"
#include "openair2/GNB_APP/gnb_paramdef.h" #include "openair2/GNB_APP/gnb_paramdef.h"
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <inttypes.h> #include <inttypes.h>
#include "log.h" #include "log.h"
#include "log_extern.h"
#include "assertions.h" #include "assertions.h"
#include "intertask_interface.h" #include "intertask_interface.h"
#include "s1ap_eNB.h" #include "s1ap_eNB.h"
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "common/utils/LOG/log.h" #include "common/utils/LOG/log.h"
#include "common/utils/nr/nr_common.h" #include "common/utils/nr/nr_common.h"
#include "common/utils/LOG/log_extern.h"
#include "assertions.h" #include "assertions.h"
#include "oai_asn1.h" #include "oai_asn1.h"
#include "executables/softmodem-common.h" #include "executables/softmodem-common.h"
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
*/ */
#include "pdcp_sequence_manager.h" #include "pdcp_sequence_manager.h"
#include "common/utils//LOG/log_if.h" #include "common/utils/LOG/log.h"
#include "pdcp_util.h" #include "pdcp_util.h"
/* /*
......
...@@ -1957,7 +1957,7 @@ static int get_mcs_from_sinr(float sinr) ...@@ -1957,7 +1957,7 @@ static int get_mcs_from_sinr(float sinr)
static int get_cqi_from_mcs(void) static int get_cqi_from_mcs(void)
{ {
static const int mcs_to_cqi[] = {0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15}; static const int mcs_to_cqi[] = {0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15};
assert(NUM_ELEMENTS(mcs_to_cqi) == NUM_MCS); assert(sizeofArray(mcs_to_cqi) == NUM_MCS);
int sf = 0; int sf = 0;
while(sf < NUM_NFAPI_SUBFRAME) while(sf < NUM_NFAPI_SUBFRAME)
{ {
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "cli.h" #include "cli.h"
#include "log.h" #include "log.h"
#include "log_extern.h"
extern cli_config *cli_cfg; extern cli_config *cli_cfg;
......
...@@ -48,7 +48,7 @@ This header file must be included */ ...@@ -48,7 +48,7 @@ This header file must be included */
#endif #endif
#ifndef project_include #ifndef project_include
#define project_include #define project_include
#include "common/utils/LOG/log_if.h" #include "common/utils/LOG/log.h"
#include "PHY/defs_RU.h" #include "PHY/defs_RU.h"
#endif #endif
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <cmath> #include <cmath>
#include <time.h> #include <time.h>
#include <limits> #include <limits>
#include "common/utils/LOG/log_extern.h" #include "common/utils/LOG/log.h"
#include "common_lib.h" #include "common_lib.h"
#include <chrono> #include <chrono>
......
...@@ -32,8 +32,7 @@ ...@@ -32,8 +32,7 @@
#include "LAYER2/RLC/AM_v9.3.0/rlc_am.h" #include "LAYER2/RLC/AM_v9.3.0/rlc_am.h"
#include "LAYER2/MAC/defs.h" #include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/vars.h" #include "LAYER2/MAC/vars.h"
#include "UTIL/LOG/log_if.h" #include "UTIL/LOG/log.h"
#include "UTIL/LOG/log_extern.h"
#include "RRC/LTE/vars.h" #include "RRC/LTE/vars.h"
#include "PHY_INTERFACE/vars.h" #include "PHY_INTERFACE/vars.h"
#include "UTIL/AT_COMMANDS/parser.h" #include "UTIL/AT_COMMANDS/parser.h"
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "MAC_INTERFACE/vars.h" #include "MAC_INTERFACE/vars.h"
#include "LAYER2/MAC/vars.h" #include "LAYER2/MAC/vars.h"
#include "UTIL/LOG/log_if.h" #include "UTIL/LOG/log.h"
#include "test_util.h" #include "test_util.h"
#include "test_pdcp.h" #include "test_pdcp.h"
......
...@@ -32,8 +32,7 @@ ...@@ -32,8 +32,7 @@
#include "LAYER2/MAC/defs.h" #include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/vars.h" #include "LAYER2/MAC/vars.h"
#include "UTIL/LOG/log_if.h" #include "UTIL/LOG/log.h"
#include "UTIL/LOG/log_extern.h"
#include "RRC/LTE/vars.h" #include "RRC/LTE/vars.h"
#include "PHY_INTERFACE/vars.h" #include "PHY_INTERFACE/vars.h"
#include "LAYER2/PDCP_v10.1.0/pdcp.h" #include "LAYER2/PDCP_v10.1.0/pdcp.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment