Commit b85cbdde authored by frtabu's avatar frtabu

log.c simplification, fix usefull functionality which never worked, move all...

log.c simplification, fix usefull functionality which never worked, move all log code from openair2 to common
parent c30a2fa6
......@@ -897,7 +897,7 @@ set(UTIL_SRC
${OPENAIR2_DIR}/UTIL/FIFO/pad_list.c
${OPENAIR2_DIR}/UTIL/LISTS/list.c
${OPENAIR2_DIR}/UTIL/LISTS/list2.c
${OPENAIR2_DIR}/UTIL/LOG/log.c
${OPENAIR_DIR}/common/utils/LOG/log.c
# ${OPENAIR2_DIR}/UTIL/LOG/vcd_signal_dumper.c
${OPENAIR2_DIR}/UTIL/MATH/oml.c
${OPENAIR2_DIR}/UTIL/MEM/mem_block.c
......@@ -2175,7 +2175,7 @@ if (${T_TRACER})
#all "add_executable" definitions (except tests, rb_tool, updatefw)
lte-softmodem lte-softmodem-nos1 lte-uesoftmodem lte-uesoftmodem-nos1
dlsim_tm4 dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim
pdcchsim pucchsim prachsim syncsim
pdcchsim pucchsim prachsim syncsim ulsim
#all "add_library" definitions
ITTI RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB
oai_exmimodevif oai_usrpdevif oai_bladerfdevif oai_lmssdrdevif
......
......@@ -37,6 +37,35 @@
#include <errno.h>
#include "config_userapi.h"
void parse_stringlist(paramdef_t *cfgoptions, char *val)
{
char *atoken;
char *tokctx;
char *tmpval=strdup(val);
int numelt=0;
cfgoptions->numelt=0;
atoken=strtok_r(tmpval, ",",&tokctx);
while(atoken != NULL) {
numelt++ ;
atoken=strtok_r(NULL, ",",&tokctx);
}
free(tmpval);
config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt);
cfgoptions->numelt=numelt;
atoken=strtok_r(val, ",",&tokctx);
for( int i=0; i<cfgoptions->numelt && atoken != NULL ; i++) {
config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(atoken)+1);
sprintf(cfgoptions->strlistptr[i],"%s",atoken);
printf_params("[LIBCONFIG] %s[%i]: %s\n", cfgoptions->optname,i,cfgoptions->strlistptr[i]);
atoken=strtok_r(NULL, ",",&tokctx);
}
cfgoptions->numelt=numelt;
}
int processoption(paramdef_t *cfgoptions, char *value)
{
char *tmpval = value;
......@@ -66,6 +95,7 @@ char defbool[2]="1";
break;
case TYPE_STRINGLIST:
parse_stringlist(cfgoptions,tmpval);
break;
case TYPE_UINT32:
case TYPE_INT32:
......@@ -140,7 +170,7 @@ char *cfgpath;
exit_fun("[CONFIG] Exiting after displaying help\n");
}
} else {
pp=strtok_r(NULL, "_",&tokctx);
pp=strtok_r(NULL, " ",&tokctx);
if ( prefix != NULL && pp != NULL && strncasecmp(prefix,pp,strlen(pp)) == 0 ) {
printf ("Help for %s section:\n",prefix);
config_printhelp(cfgoptions,numoptions);
......@@ -167,17 +197,19 @@ char *cfgpath;
((strlen(oneargv) > 2) && (strcmp(oneargv + 2,cfgpath ) == 0 )) ) {
char *valptr=NULL;
int ret;
pp = config_get_if()->argv[i+1];
if (pp != NULL && c > 1) {
ret = strlen(pp);
if (ret > 0 ) {
if (pp[0] != '-')
valptr=pp;
else if ( ret > 1 && pp[0] == '-' && isdigit(pp[1]) )
valptr=pp;
}
if (c > 0) {
pp = config_get_if()->argv[i+1];
if (pp != NULL ) {
ret = strlen(pp);
if (ret > 0 ) {
if (pp[0] != '-')
valptr=pp;
else if ( ret > 1 && pp[0] == '-' && isdigit(pp[1]) )
valptr=pp;
}
}
}
j += processoption(&(cfgoptions[n]), pp);
j += processoption(&(cfgoptions[n]), valptr);
if ( valptr != NULL ) {
i++;
c--;
......
......@@ -45,74 +45,40 @@
# include <pthread.h>
# include <string.h>
#include <linux/prctl.h>
#include "common/config/config_userapi.h"
// main log variables
typedef struct {
char* buf_p;
int buf_index;
int enable_flag;
} log_mem_cnt_t;
log_mem_cnt_t log_mem_d[2];
int log_mem_flag=0;
int log_mem_multi=1;
volatile int log_mem_side=0;
pthread_mutex_t log_mem_lock;
pthread_cond_t log_mem_notify;
pthread_t log_mem_thread;
int log_mem_file_cnt=0;
volatile int log_mem_write_flag=0;
volatile int log_mem_write_side=0;
char __log_mem_filename[1024]={0};
char * log_mem_filename = &__log_mem_filename[0];
mapping log_level_names[] = {
{"emerg", LOG_EMERG},
{"alert", LOG_ALERT},
{"crit", LOG_CRIT},
{"error", LOG_ERR},
{"warn", LOG_WARNING},
{"notice", LOG_NOTICE},
{"info", LOG_INFO},
{"debug", LOG_DEBUG},
{"file", LOG_FILE},
{"trace", LOG_TRACE},
{"matlab", LOG_MATLAB},
{NULL, -1}
};
mapping log_verbosity_names[] = {
{"none", 0x0},
{"low", 0x5},
{"medium", 0x15},
{"high", 0x35},
{"full", 0x75},
{"error", OAILOG_ERR},
{"file", OAILOG_FILE},
{"warn", OAILOG_WARNING},
{"info", OAILOG_INFO},
{"debug", OAILOG_DEBUG},
{"trace", OAILOG_TRACE},
{NULL, -1}
};
// vars for the log thread
LOG_params log_list[2000];
int log_list_tail = 0;
int log_list_nb_elements = 0;
pthread_mutex_t log_lock;
pthread_cond_t log_notify;
mapping log_options[] = {
{"nocolor", FLAG_NOCOLOR },
{"level", FLAG_LEVEL },
{"thread", FLAG_THREAD },
{NULL,-1}
};
#if !defined(LOG_NO_THREAD)
int log_list_head = 0;
int log_shutdown;
#endif
static int gfd;
mapping log_maskmap[] = {
{"prach", DEBUG_PRACH},
{"RU", DEBUG_RU},
{NULL,-1}
};
static char *log_level_highlight_start[] = {LOG_RED, LOG_RED, LOG_RED, LOG_RED, LOG_ORANGE, LOG_BLUE, "", ""}; /*!< \brief Optional start-format strings for highlighting */
static char *log_level_highlight_end[] = {LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET,LOG_RESET, "",""}; /*!< \brief Optional end-format strings for highlighting */
char *log_level_highlight_start[] = {LOG_RED, LOG_GREEN, LOG_ORANGE, "", LOG_BLUE, LOG_CYBL}; /*!< \brief Optional start-format strings for highlighting */
char *log_level_highlight_end[] = {LOG_RESET,LOG_RESET,LOG_RESET,LOG_RESET, LOG_RESET,LOG_RESET}; /*!< \brief Optional end-format strings for highlighting */
#if defined(ENABLE_ITTI)
static log_instance_type_t log_instance_type;
#endif
int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format)
{
......@@ -120,7 +86,8 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
FILE *fp=NULL;
int i;
if (data == NULL)
return -1;
//printf("Writing %d elements of type %d to %s\n",length,format,fname);
......@@ -248,7 +215,7 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
fprintf(fp,"\n%d,",((short *)data)[i]);
}
printf("\n erennnnnnnnnnnnnnn: length :%d",length);
printf("\n eren: length :%d",length);
break;
case 12 : // case eren for log2_maxh real unsigned 8 bit
......@@ -272,21 +239,35 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
/* get log parameters from configuration file */
void log_getconfig(log_t *g_log) {
char *gloglevel = NULL;
char *glogverbo = NULL;
int level,verbosity;
int level;
paramdef_t logparams_defaults[] = LOG_GLOBALPARAMS_DESC;
paramdef_t logparams_level[MAX_LOG_PREDEF_COMPONENTS];
paramdef_t logparams_verbosity[MAX_LOG_PREDEF_COMPONENTS];
paramdef_t logparams_logfile[MAX_LOG_PREDEF_COMPONENTS];
paramdef_t logparams_debug[sizeof(log_maskmap)/sizeof(mapping)];
paramdef_t logparams_matlab[sizeof(log_maskmap)/sizeof(mapping)];
int ret = config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX);
if (ret <0) {
fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed");
return;
}
for(int i=0; i<logparams_defaults[LOG_OPTIONS_IDX].numelt ; i++) {
for(int j=0; log_options[j].name != NULL ; j++) {
if (strcmp(logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i],log_options[j].name) == 0) {
g_log->flag = g_log->flag | log_options[j].value;
break;
} else if (log_options[j+1].name == NULL){
fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]);
exit(-1);
}
}
}
/* 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_verbosity,0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS);
memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS);
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) {
if(g_log->log_component[i].name == NULL) {
......@@ -294,48 +275,58 @@ void log_getconfig(log_t *g_log) {
sprintf((char *)g_log->log_component[i].name,"comp%i?",i);
logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD;
logparams_level[i].paramflags = PARAMFLAG_DONOTREAD;
logparams_verbosity[i].paramflags = PARAMFLAG_DONOTREAD;
}
sprintf(logparams_level[i].optname, LOG_CONFIG_LEVEL_FORMAT, g_log->log_component[i].name);
sprintf(logparams_verbosity[i].optname,LOG_CONFIG_VERBOSITY_FORMAT, g_log->log_component[i].name);
sprintf(logparams_logfile[i].optname, LOG_CONFIG_LOGFILE_FORMAT, g_log->log_component[i].name);
/* workaround: all log options in existing configuration files use lower case component names
where component names include uppercase char in log.h.... */
for (int j=0 ; j<strlen(logparams_level[i].optname); j++)
logparams_level[i].optname[j] = tolower(logparams_level[i].optname[j]);
for (int j=0 ; j<strlen(logparams_level[i].optname); j++)
logparams_verbosity[i].optname[j] = tolower(logparams_verbosity[i].optname[j]);
for (int j=0 ; j<strlen(logparams_level[i].optname); j++)
logparams_logfile[i].optname[j] = tolower(logparams_logfile[i].optname[j]);
/* */
logparams_level[i].defstrval = gloglevel;
logparams_verbosity[i].defstrval = glogverbo;
logparams_logfile[i].defstrval = malloc(strlen(g_log->log_component[i].name) + 16);
sprintf(logparams_logfile[i].defstrval,"/tmp/oai%s.log",g_log->log_component[i].name);
logparams_logfile[i].defuintval = 0;
logparams_logfile[i].numelt = 0;
logparams_verbosity[i].numelt = 0;
logparams_level[i].numelt = 0;
logparams_level[i].type = TYPE_STRING;
logparams_verbosity[i].type = TYPE_STRING;
logparams_logfile[i].type = TYPE_UINT;
logparams_logfile[i].paramflags = logparams_logfile[i].paramflags|PARAMFLAG_BOOL;
}
/* read the per component parameters */
config_get( logparams_level, MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX);
config_get( logparams_verbosity,MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX);
config_get( logparams_logfile, MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX);
/* 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++) {
verbosity = map_str_to_int(log_verbosity_names,*(logparams_verbosity[i].strptr));
level = map_str_to_int(log_level_names, *(logparams_level[i].strptr));
set_comp_log(i, level,verbosity,1);
/* HOTFIX: the following statement crashes, it is thus commented
* TODO: proper fix
*/
/*set_component_filelog(*(logparams_logfile[i].uptr));*/
if ( logparams_logfile[i].defstrval != NULL) {
free (logparams_logfile[i].defstrval);
}
}
set_log(i, level,1);
if (*(logparams_logfile[i].uptr) == 1)
set_component_filelog(i);
}
/* build then read the debug and matlab parameter array */
for (int i=0;log_maskmap[i].name != NULL ; i++) {
sprintf(logparams_debug[i].optname, LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name);
sprintf(logparams_matlab[i].optname, LOG_CONFIG_MATLAB_FORMAT, log_maskmap[i].name);
logparams_debug[i].defuintval = 0;
logparams_debug[i].type = TYPE_UINT;
logparams_debug[i].paramflags = PARAMFLAG_BOOL;
logparams_debug[i].numelt = 0;
logparams_matlab[i].defuintval = 0;
logparams_matlab[i].type = TYPE_UINT;
logparams_matlab[i].paramflags = PARAMFLAG_BOOL;
logparams_matlab[i].numelt = 0;
}
config_get( logparams_debug,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX);
config_get( logparams_matlab,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX);
/* set the debug mask according to the debug parameters values */
for (int i=0; log_maskmap[i].name != NULL ; i++) {
if (*(logparams_debug[i].uptr) )
g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value;
if (*(logparams_matlab[i].uptr) )
g_log->matlab_mask = g_log->matlab_mask | log_maskmap[i].value;
}
}
int register_log_component(char *name, char *fext, int compidx)
......@@ -355,10 +346,9 @@ int computed_compidx=compidx;
}
if (computed_compidx >= 0 && computed_compidx <MAX_LOG_COMPONENTS) {
g_log->log_component[computed_compidx].name = strdup(name);
g_log->log_component[computed_compidx].level = LOG_ALERT;
g_log->log_component[computed_compidx].flag = LOG_MED;
g_log->log_component[computed_compidx].level = LOG_ERR;
g_log->log_component[computed_compidx].interval = 1;
g_log->log_component[computed_compidx].fd = 0;
g_log->log_component[computed_compidx].stream = NULL;
g_log->log_component[computed_compidx].filelog = 0;
g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/<name>.%s rounded to ^2 */
sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext);
......@@ -377,9 +367,9 @@ int logInit (void)
perror ("cannot allocated memory for log generation module \n");
exit(EXIT_FAILURE);
}
memset(g_log,0,sizeof(log_t));
#if ! defined(CN_BUILD)
register_log_component("PHY","log",PHY);
register_log_component("MAC","log",MAC);
......@@ -387,7 +377,7 @@ int logInit (void)
register_log_component("RLC","log",RLC);
register_log_component("PDCP","log",PDCP);
register_log_component("RRC","log",RRC);
register_log_component("SIM","log",SIM);
register_log_component("EMU","log",EMU);
register_log_component("OMG","csv",OMG);
register_log_component("OTG","log",OTG);
register_log_component("OTG_LATENCY","dat",OTG_LATENCY);
......@@ -413,66 +403,56 @@ int logInit (void)
/* following log component are used for the localization*/
register_log_component("LOCALIZE","log",LOCALIZE);
#endif // ! defined(CN_BUILD)
register_log_component("NAS","log",NAS);
register_log_component("UDP","",UDP_);
g_log->log_component[UDP_].flag = LOG_FULL;
register_log_component("GTPV1U","",GTPU);
g_log->log_component[GTPU].flag = LOG_FULL;
register_log_component("S1AP","",S1AP);
g_log->log_component[S1AP].flag = LOG_FULL;
register_log_component("SCTP","",SCTP);
register_log_component("RRH","",RRH);
g_log->level2string[LOG_EMERG] = "G"; //EMERG
g_log->level2string[LOG_ALERT] = "A"; // ALERT
g_log->level2string[LOG_CRIT] = "C"; // CRITIC
g_log->level2string[LOG_ERR] = "E"; // ERROR
g_log->level2string[LOG_WARNING] = "W"; // WARNING
g_log->level2string[LOG_NOTICE] = "N"; // NOTICE
g_log->level2string[LOG_INFO] = "I"; //INFO
g_log->level2string[LOG_DEBUG] = "D"; // DEBUG
g_log->level2string[LOG_FILE] = "F"; // file
g_log->level2string[LOG_TRACE] = "T"; // TRACE
g_log->level2string[LOG_MATLAB] = "M"; // MATLAB
g_log->level2string[OAILOG_ERR] = "E"; // ERROR
g_log->level2string[OAILOG_WARNING] = "W"; // WARNING
g_log->level2string[OAILOG_INFO] = "I"; //INFO
g_log->level2string[OAILOG_DEBUG] = "D"; // DEBUG
g_log->level2string[OAILOG_FILE] = "F"; // file
g_log->level2string[OAILOG_TRACE] = "T"; // TRACE
g_log->onlinelog = 1; //online log file
g_log->syslog = 0;
g_log->filelog = 0;
g_log->level = LOG_TRACE;
g_log->flag = LOG_LOW;
g_log->config.remote_ip = 0;
g_log->config.remote_level = LOG_EMERG;
g_log->config.facility = LOG_LOCAL7;
g_log->config.audit_ip = 0;
g_log->config.audit_facility = LOG_LOCAL6;
g_log->config.format = 0x00; // online debug inactive
g_log->filelog_name = "/tmp/openair.log";
if (g_log->syslog) {
#if ! defined(CN_BUILD)
openlog(g_log->log_component[SIM].name, LOG_PID, g_log->config.facility);
#endif // ! defined(CN_BUILD)
}
log_getconfig(g_log);
if (g_log->filelog) {
gfd = open(g_log->filelog_name, O_WRONLY | O_CREAT, 0666);
}
// could put a loop here to check for all comps
for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
if (g_log->log_component[i].filelog == 1 ) {
g_log->log_component[i].fd = open(g_log->log_component[i].filelog_name,
O_WRONLY | O_CREAT | O_APPEND, 0666);
g_log->log_component[i].stream = fopen(g_log->log_component[i].filelog_name,"w");
g_log->log_component[i].fwrite = vfprintf;
} else if (g_log->log_component[i].filelog == 1 ) {
g_log->log_component[i].stream = fopen(g_log->filelog_name,"w");
g_log->log_component[i].fwrite = vfprintf;
} else if (g_log->onlinelog == 1 ) {
g_log->log_component[i].stream = stdout;
g_log->log_component[i].fwrite = vfprintf;
}
}
// set all unused component items to 0, they are for non predefined components
for (i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
memset(&(g_log->log_component[i]),0,sizeof(log_component_t));
......@@ -483,598 +463,46 @@ int logInit (void)
}
extern int oai_exit;
void log_mem_write(void)
{
int fp;
char f_name[1024];
struct timespec slp_tm;
slp_tm.tv_sec = 0;
slp_tm.tv_nsec = 10000;
pthread_setname_np( pthread_self(), "log_mem_write");
while (!oai_exit) {
pthread_mutex_lock(&log_mem_lock);
log_mem_write_flag=0;
pthread_cond_wait(&log_mem_notify, &log_mem_lock);
log_mem_write_flag=1;
pthread_mutex_unlock(&log_mem_lock);
// write!
if(log_mem_d[log_mem_write_side].enable_flag==0){
if(log_mem_file_cnt>1){
log_mem_file_cnt=1;
printf("log over write!!!\n");
}
snprintf(f_name,1024, "%s_%d.log",log_mem_filename,log_mem_file_cnt);
fp=open(f_name, O_WRONLY | O_CREAT, 0666);
int ret = write(fp, log_mem_d[log_mem_write_side].buf_p, log_mem_d[log_mem_write_side].buf_index);
if ( ret < 0) {
fprintf(stderr,"{LOG} %s %d Couldn't write in %s \n",__FILE__,__LINE__,f_name);
exit(EXIT_FAILURE);
}
close(fp);
log_mem_file_cnt++;
log_mem_d[log_mem_write_side].buf_index=0;
log_mem_d[log_mem_write_side].enable_flag=1;
}else{
printf("If you'd like to write log, you should set enable flag to 0!!!\n");
nanosleep(&slp_tm,NULL);
}
}
}
int logInit_log_mem (void)
{
if(log_mem_flag==1){
if(log_mem_multi==1){
printf("log-mem multi!!!\n");
log_mem_d[0].buf_p = malloc(LOG_MEM_SIZE);
log_mem_d[0].buf_index=0;
log_mem_d[0].enable_flag=1;
log_mem_d[1].buf_p = malloc(LOG_MEM_SIZE);
log_mem_d[1].buf_index=0;
log_mem_d[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_d[1].enable_flag=0;
return -1;
}
pthread_create(&log_mem_thread, NULL, (void *(*)(void *))log_mem_write, (void*)NULL);
}else{
printf("log-mem single!!!\n");
log_mem_d[0].buf_p = malloc(LOG_MEM_SIZE);
log_mem_d[0].buf_index=0;
log_mem_d[0].enable_flag=1;
log_mem_d[1].enable_flag=0;
log_mem_side=0;
}
}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;
}
printf("log init done\n");
return 0;
}
void nfapi_log(const char *file, const char *func, int line, int comp, int level, const char* format,va_list args)
{
//logRecord_mt(file,func,line, pthread_self(), comp, level, format, ##args)
int len = 0;
log_component_t *c;
char *log_start;
char *log_end;
/* The main difference with the version above is the use of this local log_buffer.
* The other difference is the return value of snprintf which was not used
* correctly. It was not a big problem because in practice MAX_LOG_TOTAL is
* big enough so that the buffer is never full.
*/
char log_buffer[MAX_LOG_TOTAL];
/* for no gcc warnings */
(void)log_start;
(void)log_end;
c = &g_log->log_component[comp];
// do not apply filtering for LOG_F
// only log messages which are enabled and are below the global log level and component's level threshold
if ((level != LOG_FILE) && ((level > c->level) || (level > g_log->level))) {
/* if ((level != LOG_FILE) &&
((level > c->level) ||
(level > g_log->level) ||
( c->level > g_log->level))) {
*/
return;
}
//VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, VCD_FUNCTION_IN);
// adjust syslog level for TRACE messages
if (g_log->syslog) {
if (g_log->level > LOG_DEBUG) {
g_log->level = LOG_DEBUG;
}
}
// make sure that for log trace the extra info is only printed once, reset when the level changes
if ((level == LOG_FILE) || (c->flag == LOG_NONE) || (level == LOG_TRACE)) {
log_start = log_buffer;
len = vsnprintf(log_buffer, MAX_LOG_TOTAL, format, args);
if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
log_end = log_buffer + len;
} else {
if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) {
len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "%s",
log_level_highlight_start[level]);
if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
}
log_start = log_buffer + len;
if ( (g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ) {
len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]",
g_log->log_component[comp].name);
if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
}
if ( (g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL) ) {
len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]",
g_log->level2string[level]);
if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
}
if ( (g_log->flag & FLAG_THREAD) || (c->flag & FLAG_THREAD) ) {
# define THREAD_NAME_LEN 128
char threadname[THREAD_NAME_LEN];
if (pthread_getname_np(pthread_self(), threadname, THREAD_NAME_LEN) != 0)
char *log_getthreadname(char *threadname) {
if (pthread_getname_np(pthread_self(), threadname, sizeof(threadname)) != 0)
{
perror("pthread_getname_np : ");
return "thread?";
} else {
len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", threadname);
if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
}
# undef THREAD_NAME_LEN
}
if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) {
len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s] ",
func);
if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
}
if ( (g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) {