Commit 6f3adad3 authored by Cedric Roux's avatar Cedric Roux

- Refine logs functions to avoid copies

- Make logs functions "task-aware"

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4281 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 129ccac0
...@@ -40,51 +40,51 @@ ...@@ -40,51 +40,51 @@
#define COMPONENT_LOG #define COMPONENT_LOG
#define COMPONENT_LOG_IF #define COMPONENT_LOG_IF
//static unsigned char fifo_print_buffer[FIFO_PRINTF_MAX_STRING_SIZE];
#include "log.h" #include "log.h"
#include "log_vars.h"
#include "vcd_signal_dumper.h" #include "vcd_signal_dumper.h"
#include "assertions.h"
//#include "UTIL/OCG/OCG.h"
//#include "UTIL/OCG/OCG_extern.h"
#ifdef USER_MODE #ifdef USER_MODE
# include <pthread.h> # include <pthread.h>
# include <string.h> # include <string.h>
#endif #endif
#ifdef RTAI #ifdef RTAI
#include <rtai.h> # include <rtai.h>
#include <rtai_fifos.h> # include <rtai_fifos.h>
# define FIFO_PRINTF_MAX_STRING_SIZE 1000 # define FIFO_PRINTF_MAX_STRING_SIZE 1000
# define FIFO_PRINTF_NO 62 # define FIFO_PRINTF_NO 62
# define FIFO_PRINTF_SIZE 65536 # define FIFO_PRINTF_SIZE 65536
#endif #endif
// made static and not local to logRecord() for performance reasons // main log variables
static char g_buff_tmp [MAX_LOG_ITEM]; log_t *g_log;
static char g_buff_info [MAX_LOG_INFO];
static char g_buff_total[MAX_LOG_TOTAL];
static int gfd;
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 */ // vars for the log thread
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 */ 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;
// static int bypass_log_hdr; #if !defined(LOG_NO_THREAD)
int log_list_head = 0;
int log_shutdown;
#endif
//extern MAC_xface *mac_xface; static int gfd;
int logInit (void) { 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 */
int logInit (void)
{
#ifdef USER_MODE #ifdef USER_MODE
int i; int i;
g_log = calloc(1, sizeof(log_t)); g_log = calloc(1, sizeof(log_t));
#else #else
g_log = kmalloc(sizeof(log_t),GFP_KERNEL); g_log = kmalloc(sizeof(log_t), GFP_KERNEL);
#endif #endif
if (g_log == NULL) { if (g_log == NULL) {
#ifdef USER_MODE #ifdef USER_MODE
...@@ -184,7 +184,6 @@ int logInit (void) { ...@@ -184,7 +184,6 @@ int logInit (void) {
g_log->log_component[OTG_LATENCY_BG].filelog = 0; g_log->log_component[OTG_LATENCY_BG].filelog = 0;
g_log->log_component[OTG_LATENCY_BG].filelog_name = "/tmp/otg_latency_bg.dat"; g_log->log_component[OTG_LATENCY_BG].filelog_name = "/tmp/otg_latency_bg.dat";
g_log->log_component[OTG_GP].name = "OTG_GP"; g_log->log_component[OTG_GP].name = "OTG_GP";
g_log->log_component[OTG_GP].level = LOG_EMERG; g_log->log_component[OTG_GP].level = LOG_EMERG;
g_log->log_component[OTG_GP].flag = LOG_MED; g_log->log_component[OTG_GP].flag = LOG_MED;
...@@ -259,11 +258,11 @@ int logInit (void) { ...@@ -259,11 +258,11 @@ int logInit (void) {
g_log->log_component[S1AP].name = "S1AP"; g_log->log_component[S1AP].name = "S1AP";
g_log->log_component[S1AP].level = LOG_EMERG; g_log->log_component[S1AP].level = LOG_EMERG;
g_log->log_component[S1AP].flag = LOG_MED; g_log->log_component[S1AP].flag = LOG_FULL;
g_log->log_component[S1AP].interval = 1; g_log->log_component[S1AP].interval = 1;
g_log->log_component[S1AP].fd = 0; g_log->log_component[S1AP].fd = 0;
g_log->log_component[S1AP].filelog = 0; g_log->log_component[S1AP].filelog = 0;
g_log->log_component[S1AP].filelog_name = "/tmp/s1ap.log"; g_log->log_component[S1AP].filelog_name = "";
g_log->log_component[SCTP].name = "SCTP"; g_log->log_component[SCTP].name = "SCTP";
g_log->log_component[SCTP].level = LOG_EMERG; g_log->log_component[SCTP].level = LOG_EMERG;
...@@ -323,9 +322,11 @@ int logInit (void) { ...@@ -323,9 +322,11 @@ int logInit (void) {
gfd = open(g_log->filelog_name, O_WRONLY | O_CREAT, 0666); gfd = open(g_log->filelog_name, O_WRONLY | O_CREAT, 0666);
} }
// could put a loop here to check for all comps // could put a loop here to check for all comps
for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++){ for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
if (g_log->log_component[i].filelog == 1 ) 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].fd = open(g_log->log_component[i].filelog_name,
O_WRONLY | O_CREAT | O_APPEND, 0666);
}
} }
#else #else
g_log->syslog = 0; g_log->syslog = 0;
...@@ -343,14 +344,12 @@ int logInit (void) { ...@@ -343,14 +344,12 @@ int logInit (void) {
} }
//log record: add to a list //log record: add to a list
void logRecord( const char *file, const char *func, void logRecord(const char *file, const char *func, int line, int comp,
int line, int comp, int level, int level, char *format, ...)
char *format, ...) { {
va_list args; va_list args;
LOG_params log_params; LOG_params log_params;
int len; int len;
//LOG_elt *log = NULL;
va_start(args, format); va_start(args, format);
len = vsnprintf(log_params.l_buff_info, MAX_LOG_INFO-1, format, args); len = vsnprintf(log_params.l_buff_info, MAX_LOG_INFO-1, format, args);
...@@ -365,15 +364,25 @@ void logRecord( const char *file, const char *func, ...@@ -365,15 +364,25 @@ void logRecord( const char *file, const char *func,
log_params.format = format; log_params.format = format;
log_params.len = len; log_params.len = len;
if(pthread_mutex_lock(&log_lock) != 0) { return; } if (pthread_mutex_lock(&log_lock) != 0) {
return;
}
log_list_tail++; log_list_tail++;
log_list[log_list_tail - 1] = log_params; log_list[log_list_tail - 1] = log_params;
if (log_list_tail >= 1000) log_list_tail = 0; if (log_list_tail >= 1000) {
if (log_list_nb_elements < 1000) log_list_nb_elements++; log_list_tail = 0;
if(pthread_cond_signal(&log_notify) != 0) { return; } }
if (log_list_nb_elements < 1000) {
log_list_nb_elements++;
}
if(pthread_cond_signal(&log_notify) != 0) {
return;
}
if(pthread_mutex_unlock(&log_lock) != 0) { return; } if(pthread_mutex_unlock(&log_lock) != 0) {
return;
}
//log = malloc(sizeof(LOG_elt)); //log = malloc(sizeof(LOG_elt));
//log->next = NULL; //log->next = NULL;
...@@ -385,25 +394,25 @@ void logRecord( const char *file, const char *func, ...@@ -385,25 +394,25 @@ void logRecord( const char *file, const char *func,
void logRecord_thread_safe(const char *file, const char *func, void logRecord_thread_safe(const char *file, const char *func,
int line, int comp, int level, int line, int comp, int level,
int len, const char *params_string) { int len, const char *params_string)
{
log_component_t *c; log_component_t *c;
int total_len = 0;
char log_buffer[MAX_LOG_TOTAL];
sprintf(g_buff_info, "%s", params_string);
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,1);
g_buff_total[0] = '\0';
c = &g_log->log_component[comp]; c = &g_log->log_component[comp];
// do not apply filtering for LOG_F // 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 // only log messages which are enabled and are below the global log level and component's level threshold
if ( (level != LOG_FILE) && ( (c->level > g_log->level) || (level > c->level) || (level > g_log->level)) ){ if ((level != LOG_FILE) && ((c->level > g_log->level) ||
// || ((mac_xface->frame % c->interval) != 0)) { (level > c->level) || (level > g_log->level)))
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,0); {
return; return;
} }
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,
VCD_FUNCTION_IN);
// adjust syslog level for TRACE messages // adjust syslog level for TRACE messages
if (g_log->syslog) { if (g_log->syslog) {
if (g_log->level > LOG_DEBUG) { if (g_log->level > LOG_DEBUG) {
...@@ -411,64 +420,43 @@ void logRecord_thread_safe(const char *file, const char *func, ...@@ -411,64 +420,43 @@ void logRecord_thread_safe(const char *file, const char *func,
} }
} }
//if (level == LOG_TRACE)
//exit(-1);
//printf (g_buff_info);
//return;
// make sure that for log trace the extra info is only printed once, reset when the level changes // 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 )){ if ((level == LOG_FILE) || (c->flag == LOG_NONE) || (level ==LOG_TRACE )) {
strncat(g_buff_total, g_buff_info, MAX_LOG_TOTAL-1); total_len = snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - 1, "%s",
} params_string);
else{ } else {
if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { if ((g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR)) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "%s", total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "%s",
log_level_highlight_start[level]); log_level_highlight_start[level]);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
if ( (g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ){ if ((g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "[%s]", total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "[%s]",
g_log->log_component[comp].name); g_log->log_component[comp].name);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
if ( (g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL) ){ if ((g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL)) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "[%s]", total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "[%s]",
g_log->level2string[level]); g_log->level2string[level]);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) { if ((g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT)) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "[%s] ", total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "[%s] ",
func); func);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
if ( (g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) { if ((g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "[%s:%d]", total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "[%s:%d]",
file,line); file, line);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
strncat(g_buff_total, g_buff_info, MAX_LOG_TOTAL-1);
len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - len, "%s",
params_string);
if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { if ((g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR)) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "%s", total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "%s",
log_level_highlight_end[level]); log_level_highlight_end[level]);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
/* // log trace and not reach a new line with 3 bytes
if ((level == LOG_TRACE) && (is_newline(g_buff_info,3) == 0 )){
bypass_log_hdr = 1;
}
else
bypass_log_hdr = 0;
*/
// strncat(g_buff_total, "\n", MAX_LOG_TOTAL);
} }
// OAI printf compatibility // OAI printf compatibility
...@@ -478,31 +466,32 @@ else ...@@ -478,31 +466,32 @@ else
rt_printk ("[OPENAIR] FIFO_PRINTF WROTE OUTSIDE ITS MEMORY BOUNDARY : ERRORS WILL OCCUR\n"); rt_printk ("[OPENAIR] FIFO_PRINTF WROTE OUTSIDE ITS MEMORY BOUNDARY : ERRORS WILL OCCUR\n");
} }
if (len > 0) { if (len > 0) {
rtf_put (FIFO_PRINTF_NO, g_buff_total, len); rtf_put (FIFO_PRINTF_NO, log_buffer, len);
} }
#else #else
printf("%s",g_buff_total); fprintf(stdout, "%s", log_buffer);
#endif #endif
} }
#ifndef RTAI #ifndef RTAI
if (g_log->syslog) { if (g_log->syslog) {
syslog(g_log->level, g_buff_total); syslog(g_log->level, "%s", log_buffer);
} }
if (g_log->filelog) { if (g_log->filelog) {
write(gfd, g_buff_total, strlen(g_buff_total)); write(gfd, log_buffer, total_len);
} }
if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) { if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) {
write(g_log->log_component[comp].fd, g_buff_total, strlen(g_buff_total)); write(g_log->log_component[comp].fd, log_buffer, total_len);
} }
#endif #endif
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,0); vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,
VCD_FUNCTION_OUT);
} }
#if !defined(LOG_NO_THREAD) #if !defined(LOG_NO_THREAD)
void *log_thread_function(void * list) { void *log_thread_function(void *list)
{
LOG_params log_params; LOG_params log_params;
...@@ -521,7 +510,7 @@ void *log_thread_function(void * list) { ...@@ -521,7 +510,7 @@ void *log_thread_function(void * list) {
pthread_cond_wait(&log_notify, &log_lock); pthread_cond_wait(&log_notify, &log_lock);
} }
// exit // exit
if((log_shutdown==1) && (log_list_nb_elements == 0)) { if ((log_shutdown==1) && (log_list_nb_elements == 0)) {
break; break;
} }
...@@ -530,7 +519,9 @@ void *log_thread_function(void * list) { ...@@ -530,7 +519,9 @@ void *log_thread_function(void * list) {
log_params = log_list[log_list_head]; log_params = log_list[log_list_head];
log_list_head++; log_list_head++;
log_list_nb_elements--; log_list_nb_elements--;
if (log_list_head >= 1000) log_list_head = 0; if (log_list_head >= 1000) {
log_list_head = 0;
}
/* Unlock */ /* Unlock */
...@@ -551,94 +542,72 @@ void *log_thread_function(void * list) { ...@@ -551,94 +542,72 @@ void *log_thread_function(void * list) {
#endif #endif
//log record, format, and print: executed in the main thread (mt) //log record, format, and print: executed in the main thread (mt)
void logRecord_mt( const char *file, const char *func, void logRecord_mt(const char *file, const char *func, int line, int comp,
int line, int comp, int level, int level, char *format, ...)
char *format, ...) { {
int len = 0;
int len;
va_list args; va_list args;
log_component_t *c; log_component_t *c;
g_buff_total[0] = '\0';
c = &g_log->log_component[comp]; c = &g_log->log_component[comp];
// do not apply filtering for LOG_F // 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 // only log messages which are enabled and are below the global log level and component's level threshold
if ( (level != LOG_FILE) && ( (c->level > g_log->level) || (level > c->level) || (level > g_log->level)) ){ if ((level != LOG_FILE) && ((c->level > g_log->level) || (level > c->level)
// || ((mac_xface->frame % c->interval) != 0)) { || (level > g_log->level))) {
return; return;
} }
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,1);
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,
VCD_FUNCTION_IN);
va_start(args, format);
// adjust syslog level for TRACE messages // adjust syslog level for TRACE messages
if (g_log->syslog) { if (g_log->syslog) {
if (g_log->level > LOG_DEBUG) { if (g_log->level > LOG_DEBUG) {
g_log->level = LOG_DEBUG; g_log->level = LOG_DEBUG;
} }
} }
va_start(args, format);
len=vsnprintf(g_buff_info, MAX_LOG_INFO-1, format, args);
va_end(args);
//if (level == LOG_TRACE)
//exit(-1);
//printf (g_buff_info);
//return;
// make sure that for log trace the extra info is only printed once, reset when the level changes // 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 )){ if ((level == LOG_FILE) || (c->flag == LOG_NONE) || (level == LOG_TRACE)) {
strncat(g_buff_total, g_buff_info, MAX_LOG_TOTAL-1); len = vsnprintf(c->log_buffer, MAX_LOG_TOTAL-1, format, args);
} } else {
else{
if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "%s", len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "%s",
log_level_highlight_start[level]); log_level_highlight_start[level]);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
if ( (g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ){ if ( (g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "[%s]", len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "[%s]",
g_log->log_component[comp].name); g_log->log_component[comp].name);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
if ( (g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL) ){ if ( (g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL) ) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "[%s]", len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "[%s]",
g_log->level2string[level]); g_log->level2string[level]);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) { if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "[%s] ", len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "[%s] ",
func); func);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
if ( (g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) { if ( (g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "[%s:%d]", len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "[%s:%d]",
file,line); file, line);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
strncat(g_buff_total, g_buff_info, MAX_LOG_TOTAL-1);
len += vsnprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, format, args);
if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) {
len+=snprintf(g_buff_tmp, MAX_LOG_ITEM, "%s", len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "%s",
log_level_highlight_end[level]); log_level_highlight_end[level]);
strncat(g_buff_total, g_buff_tmp, MAX_LOG_TOTAL-1);
} }
/* // log trace and not reach a new line with 3 bytes
if ((level == LOG_TRACE) && (is_newline(g_buff_info,3) == 0 )){
bypass_log_hdr = 1;
} }
else
bypass_log_hdr = 0;
*/
va_end(args);
// strncat(g_buff_total, "\n", MAX_LOG_TOTAL);
}
// OAI printf compatibility // OAI printf compatibility
if ((g_log->onlinelog == 1) && (level != LOG_FILE)) if ((g_log->onlinelog == 1) && (level != LOG_FILE))
...@@ -647,32 +616,39 @@ void logRecord_mt( const char *file, const char *func, ...@@ -647,32 +616,39 @@ void logRecord_mt( const char *file, const char *func,
rt_printk ("[OPENAIR] FIFO_PRINTF WROTE OUTSIDE ITS MEMORY BOUNDARY : ERRORS WILL OCCUR\n"); rt_printk ("[OPENAIR] FIFO_PRINTF WROTE OUTSIDE ITS MEMORY BOUNDARY : ERRORS WILL OCCUR\n");
} }
if (len > 0) { if (len > 0) {
rtf_put (FIFO_PRINTF_NO, g_buff_total, len); rtf_put (FIFO_PRINTF_NO, c->log_buffer, len);
} }
#else #else
printf("%s",g_buff_total); fprintf(stdout, "%s", c->log_buffer);
#endif #endif
#ifndef RTAI #ifndef RTAI
if (g_log->syslog) { if (g_log->syslog) {
syslog(g_log->level, g_buff_total); syslog(g_log->level, "%s", c->log_buffer);
} }
if (g_log->filelog) { if (g_log->filelog) {
write(gfd, g_buff_total, strlen(g_buff_total)); write(gfd, c->log_buffer, len);
} }
if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) { if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) {
write(g_log->log_component[comp].fd, g_buff_total, strlen(g_buff_total)); write(g_log->log_component[comp].fd, c->log_buffer, len);
} }
#endif #endif
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,0); vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD,
VCD_FUNCTION_OUT);
} }
int set_log(int component, int level, int interval) {
if ((component >=MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS)){ int set_log(int component, int level, int interval)
if ((level <= LOG_TRACE) && (level >= LOG_EMERG)){ {
/* Checking parameters */
DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS),
component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS);
DevCheck((level <= LOG_TRACE) && (level >= LOG_EMERG), level, LOG_TRACE,
LOG_EMERG);
DevCheck((interval > 0) && (interval <= 0xFF), interval, 0, 0xFF);
g_log->log_component[component].level = level; g_log->log_component[component].level = level;
switch (level) { switch (level) {
case LOG_TRACE: case LOG_TRACE:
g_log->log_component[component].flag = LOG_MED ; g_log->log_component[component].flag = LOG_MED ;
...@@ -687,54 +663,60 @@ int set_log(int component, int level, int interval) { ...@@ -687,54 +663,60 @@ int set_log(int component, int level, int interval) {
g_log->log_component[component].flag = LOG_NONE ; g_log->log_component[component].flag = LOG_NONE ;
break; break;
} }
}
if ((interval > 0) && (interval <= 0xFF)){
g_log->log_component[component].interval = interval; g_log->log_component[component].interval = interval;
}
return 0; return 0;
}
else
return -1;
} }
int set_comp_log(int component, int level, int verbosity, int interval) { int set_comp_log(int component, int level, int verbosity, int interval)
{
if ((component >=MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS)){ /* Checking parameters */
if ((verbosity == LOG_NONE) || (verbosity == LOG_LOW) || (verbosity == LOG_MED) || (verbosity == LOG_FULL) || (verbosity == LOG_HIGH) ) { DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS),
component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS);
DevCheck((level <= LOG_TRACE) && (level >= LOG_EMERG), level, LOG_TRACE,
LOG_EMERG);
DevCheck((interval > 0) && (interval <= 0xFF), interval, 0, 0xFF);
if ((verbosity == LOG_NONE) || (verbosity == LOG_LOW) ||
(verbosity == LOG_MED) || (verbosity == LOG_FULL) ||
(verbosity == LOG_HIGH)) {
g_log->log_component[component].flag = verbosity; g_log->log_component[component].flag = verbosity;
} }
if ((level <= LOG_TRACE) && (level >= LOG_EMERG)){
g_log->log_component[component].level = level; g_log->log_component[component].level = level;
}
if ((interval > 0) && (interval <= 0xFF)){
g_log->log_component[component].interval = interval; g_log->log_component[component].interval = interval;
}
return 0; return 0;
}
else
return -1;
} }
void set_glog(int level, int verbosity) { void set_glog(int level, int verbosity)
{
g_log->level = level; g_log->level = level;
g_log->flag = verbosity; g_log->flag = verbosity;
} }
void set_glog_syslog(int enable) { void set_glog_syslog(int enable)
{
g_log->syslog = enable; g_log->syslog = enable;
} }
void set_glog_onlinelog(int enable) { void set_glog_onlinelog(int enable)
{
g_log->onlinelog = enable; g_log->onlinelog = enable;
} }
void set_glog_filelog(int enable) { void set_glog_filelog(int enable)
{
g_log->filelog = enable; g_log->filelog = enable;
} }
void set_component_filelog(int comp){ void set_component_filelog(int comp)
{
if (g_log->log_component[comp].filelog == 0){ if (g_log->log_component[comp].filelog == 0) {
g_log->log_component[comp].filelog = 1; g_log->log_component[comp].filelog = 1;
if (g_log->log_component[comp].fd == 0) if (g_log->log_component[comp].fd == 0) {
g_log->log_component[comp].fd = open(g_log->log_component[comp].filelog_name, O_WRONLY | O_CREAT | O_TRUNC, 0666); g_log->log_component[comp].fd = open(g_log->log_component[comp].filelog_name,
O_WRONLY | O_CREAT | O_TRUNC, 0666);
}
} }
} }
...@@ -743,7 +725,8 @@ void set_component_filelog(int comp){ ...@@ -743,7 +725,8 @@ void set_component_filelog(int comp){
* with string value NULL * with string value NULL
*/ */
/* map a string to an int. Takes a mapping array and a string as arg */ /* map a string to an int. Takes a mapping array and a string as arg */
int map_str_to_int(mapping *map, const char *str){ int map_str_to_int(mapping *map, const char *str)
{
while (1) { while (1) {
if (map->name == NULL) { if (map->name == NULL) {
return(-1); return(-1);
...@@ -756,7 +739,8 @@ int map_str_to_int(mapping *map, const char *str){ ...@@ -756,7 +739,8 @@ int map_str_to_int(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(mapping *map, int val) { char *map_int_to_str(mapping *map, int val)
{
while (1) { while (1) {
if (map->name == NULL) { if (map->name == NULL) {
return NULL; return NULL;
...@@ -767,16 +751,21 @@ char *map_int_to_str(mapping *map, int val) { ...@@ -767,16 +751,21 @@ char *map_int_to_str(mapping *map, int val) {
map++; map++;
} }
} }
int is_newline( char *str, int size){
int is_newline( char *str, int size)
{
int i; int i;
for ( i = 0; i < size; i++ ) { for ( i = 0; i < size; i++ ) {
if ( str[i] == '\n' ) if ( str[i] == '\n' ) {
return 1; return 1;
} }
}
/* if we get all the way to here, there must not have been a newline! */ /* if we get all the way to here, there must not have been a newline! */
return 0; return 0;
} }
void logClean (void) {
void logClean (void)
{
int i; int i;
#ifdef RTAI #ifdef RTAI
rtf_destroy (FIFO_PRINTF_NO); rtf_destroy (FIFO_PRINTF_NO);
...@@ -787,19 +776,19 @@ void logClean (void) { ...@@ -787,19 +776,19 @@ void logClean (void) {
if (g_log->filelog) { if (g_log->filelog) {
close(gfd); close(gfd);
} }
for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++){ for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
if (g_log->log_component[i].filelog) if (g_log->log_component[i].filelog) {
close(g_log->log_component[i].fd); close(g_log->log_component[i].fd);
} }
}
#endif #endif
} }
#ifdef LOG_TEST #ifdef LOG_TEST
int int main(int argc, char *argv[])
main(int argc, char *argv[]) { {
logInit(); logInit();
...@@ -809,8 +798,8 @@ main(int argc, char *argv[]) { ...@@ -809,8 +798,8 @@ main(int argc, char *argv[]) {
return 1; return 1;
} }
int test_log(){ int test_log(void)
{
LOG_ENTER(MAC); // because the default level is DEBUG LOG_ENTER(MAC); // because the default level is DEBUG
LOG_I(EMU, "1 Starting OAI logs version %s Build date: %s on %s\n", LOG_I(EMU, "1 Starting OAI logs version %s Build date: %s on %s\n",
BUILD_VERSION, BUILD_DATE, BUILD_HOST); BUILD_VERSION, BUILD_DATE, BUILD_HOST);
...@@ -875,5 +864,6 @@ int test_log(){ ...@@ -875,5 +864,6 @@ int test_log(){
LOG_I(MAC, "6 info MAC \n"); LOG_I(MAC, "6 info MAC \n");
LOG_EXIT(MAC); LOG_EXIT(MAC);
return 0;
} }
#endif #endif
...@@ -233,7 +233,7 @@ extern "C" { ...@@ -233,7 +233,7 @@ extern "C" {
typedef enum { typedef enum {
MIN_LOG_COMPONENTS = 0, MIN_LOG_COMPONENTS = 0,
PHY, PHY = MIN_LOG_COMPONENTS,
MAC, MAC,
EMU, EMU,
OCG, OCG,
...@@ -275,7 +275,10 @@ typedef struct { ...@@ -275,7 +275,10 @@ typedef struct {
int interval; int interval;
int fd; int fd;
int filelog; int filelog;
char* filelog_name; char *filelog_name;
/* SR: make the log buffer component relative */
char log_buffer[MAX_LOG_TOTAL];
}log_component_t; }log_component_t;
typedef struct { typedef struct {
...@@ -285,7 +288,7 @@ typedef struct { ...@@ -285,7 +288,7 @@ typedef struct {
int facility; int facility;
int audit_facility; int audit_facility;
int format; int format;
}log_config_t; } log_config_t;
typedef struct { typedef struct {
...@@ -311,6 +314,14 @@ typedef struct LOG_params { ...@@ -311,6 +314,14 @@ typedef struct LOG_params {
int len; int len;
} LOG_params; } LOG_params;
extern log_t *g_log;
#if !defined(LOG_NO_THREAD)
extern LOG_params log_list[2000];
extern pthread_mutex_t log_lock;
extern pthread_cond_t log_notify;
extern int log_shutdown;
#endif
/*--- INCLUDES ---------------------------------------------------------------*/ /*--- INCLUDES ---------------------------------------------------------------*/
# include "log_if.h" # include "log_if.h"
......
extern log_t *g_log;
extern LOG_params log_list[2000];
extern pthread_mutex_t log_lock;
extern pthread_cond_t log_notify;
extern int log_shutdown;
// main log variables
log_t *g_log;
// vars for the log thread
LOG_params log_list[2000];
int log_list_head = 0;
int log_list_tail = 0;
int log_list_nb_elements = 0;
pthread_mutex_t log_lock;
pthread_cond_t log_notify;
int log_shutdown;
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