|
|
|
@ -65,173 +65,128 @@ void log_filter::init(std::string layer, logger *logger_, bool tti)
|
|
|
|
|
do_tti = tti;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log_filter::all_log(srslte::LOG_LEVEL_ENUM level,
|
|
|
|
|
uint32_t tti,
|
|
|
|
|
const char *msg)
|
|
|
|
|
void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, const char* msg, const uint8_t* hex, int size)
|
|
|
|
|
{
|
|
|
|
|
if(logger_h) {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
|
|
ss << now_time() << " ";
|
|
|
|
|
if (show_layer_en) {
|
|
|
|
|
ss << "[" <<get_service_name() << "] ";
|
|
|
|
|
}
|
|
|
|
|
if (level_text_short) {
|
|
|
|
|
ss << log_level_text_short[level] << " ";
|
|
|
|
|
} else {
|
|
|
|
|
ss << log_level_text[level] << " ";
|
|
|
|
|
}
|
|
|
|
|
if(do_tti) {
|
|
|
|
|
ss << "[" << std::setfill('0') << std::setw(5) << tti << "] ";
|
|
|
|
|
}
|
|
|
|
|
if (add_string_en) {
|
|
|
|
|
ss << add_string_val << " ";
|
|
|
|
|
}
|
|
|
|
|
ss << msg;
|
|
|
|
|
char buffer_tti[16];
|
|
|
|
|
char buffer_time[64];
|
|
|
|
|
|
|
|
|
|
str_ptr s_ptr(new std::string(ss.str()));
|
|
|
|
|
logger_h->log(s_ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log_filter::all_log(srslte::LOG_LEVEL_ENUM level,
|
|
|
|
|
uint32_t tti,
|
|
|
|
|
const char *msg,
|
|
|
|
|
const uint8_t *hex,
|
|
|
|
|
int size)
|
|
|
|
|
{
|
|
|
|
|
if (logger_h) {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
|
|
ss << now_time() << " ";
|
|
|
|
|
if (show_layer_en) {
|
|
|
|
|
ss << "[" <<get_service_name() << "] ";
|
|
|
|
|
}
|
|
|
|
|
if (level_text_short) {
|
|
|
|
|
ss << log_level_text_short[level] << " ";
|
|
|
|
|
} else {
|
|
|
|
|
ss << log_level_text[level] << " ";
|
|
|
|
|
}
|
|
|
|
|
logger::unique_log_str_t log_str = allocate_unique_log_str(logger_h->get_pool());
|
|
|
|
|
|
|
|
|
|
if (log_str) {
|
|
|
|
|
now_time(buffer_time, sizeof(buffer_time));
|
|
|
|
|
if (do_tti) {
|
|
|
|
|
ss << "[" << std::setfill('0') << std::setw(5) << tti << "] ";
|
|
|
|
|
get_tti_str(tti, buffer_tti, sizeof(buffer_tti));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (add_string_en) {
|
|
|
|
|
ss << add_string_val << " ";
|
|
|
|
|
}
|
|
|
|
|
ss << msg;
|
|
|
|
|
|
|
|
|
|
if (msg[strlen(msg)-1] != '\n') {
|
|
|
|
|
ss << std::endl;
|
|
|
|
|
}
|
|
|
|
|
snprintf(log_str->msg,
|
|
|
|
|
log_str->size,
|
|
|
|
|
"%s [%s] %s %s%s%s%s%s",
|
|
|
|
|
buffer_time,
|
|
|
|
|
get_service_name().c_str(),
|
|
|
|
|
log_level_text_short[level],
|
|
|
|
|
do_tti ? buffer_tti : "",
|
|
|
|
|
add_string_en ? add_string_val.c_str() : "",
|
|
|
|
|
msg,
|
|
|
|
|
msg[strlen(msg) - 1] != '\n' ? "\n" : "",
|
|
|
|
|
(hex_limit > 0 && hex && size > 0) ? hex_string(hex, size).c_str() : "");
|
|
|
|
|
|
|
|
|
|
if (hex_limit > 0 && hex && size > 0) {
|
|
|
|
|
ss << hex_string(hex, size);
|
|
|
|
|
logger_h->log(std::move(log_str));
|
|
|
|
|
} else {
|
|
|
|
|
logger_h->log_char("Error in Log: Not enough buffers in pool\n");
|
|
|
|
|
}
|
|
|
|
|
str_ptr s_ptr(new std::string(ss.str()));
|
|
|
|
|
logger_h->log(s_ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log_filter::console(const char * message, ...) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
printf("%s",args_msg); // Print directly to stdout
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log_filter::error(const char * message, ...) {
|
|
|
|
|
if (level >= LOG_LEVEL_ERROR) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
all_log(LOG_LEVEL_ERROR, tti, args_msg);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void log_filter::warning(const char * message, ...) {
|
|
|
|
|
if (level >= LOG_LEVEL_WARNING) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
all_log(LOG_LEVEL_WARNING, tti, args_msg);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void log_filter::info(const char * message, ...) {
|
|
|
|
|
if (level >= LOG_LEVEL_INFO) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
all_log(LOG_LEVEL_INFO, tti, args_msg);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void log_filter::debug(const char * message, ...) {
|
|
|
|
|
if (level >= LOG_LEVEL_DEBUG) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
all_log(LOG_LEVEL_DEBUG, tti, args_msg);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log_filter::error_hex(const uint8_t *hex, int size, const char * message, ...) {
|
|
|
|
|
if (level >= LOG_LEVEL_ERROR) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
all_log(LOG_LEVEL_ERROR, tti, args_msg, hex, size);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void log_filter::warning_hex(const uint8_t *hex, int size, const char * message, ...) {
|
|
|
|
|
if (level >= LOG_LEVEL_WARNING) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
all_log(LOG_LEVEL_WARNING, tti, args_msg, hex, size);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void log_filter::info_hex(const uint8_t *hex, int size, const char * message, ...) {
|
|
|
|
|
if (level >= LOG_LEVEL_INFO) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
all_log(LOG_LEVEL_INFO, tti, args_msg, hex, size);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void log_filter::debug_hex(const uint8_t *hex, int size, const char * message, ...) {
|
|
|
|
|
if (level >= LOG_LEVEL_DEBUG) {
|
|
|
|
|
char *args_msg = NULL;
|
|
|
|
|
char args_msg[char_buff_size];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
if(vasprintf(&args_msg, message, args) > 0)
|
|
|
|
|
if (vsnprintf(args_msg, char_buff_size, message, args) > 0)
|
|
|
|
|
all_log(LOG_LEVEL_DEBUG, tti, args_msg, hex, size);
|
|
|
|
|
va_end(args);
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -239,42 +194,48 @@ void log_filter::set_time_src(time_itf *source, time_format_t format) {
|
|
|
|
|
this->time_src = source;
|
|
|
|
|
this->time_format = format;
|
|
|
|
|
}
|
|
|
|
|
void log_filter::get_tti_str(const uint32_t tti_, char* buffer, const uint32_t buffer_len)
|
|
|
|
|
{
|
|
|
|
|
snprintf(buffer, buffer_len, "[%5d] ", tti_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string log_filter::now_time()
|
|
|
|
|
void log_filter::now_time(char* buffer, const uint32_t buffer_len)
|
|
|
|
|
{
|
|
|
|
|
struct timeval rawtime;
|
|
|
|
|
struct tm * timeinfo;
|
|
|
|
|
char buffer[64];
|
|
|
|
|
char us[16];
|
|
|
|
|
|
|
|
|
|
srslte_timestamp_t now;
|
|
|
|
|
uint64_t usec_epoch;
|
|
|
|
|
|
|
|
|
|
if (buffer_len < 16) {
|
|
|
|
|
fprintf(stderr, "Error buffer provided for time too small\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!time_src) {
|
|
|
|
|
gettimeofday(&rawtime, NULL);
|
|
|
|
|
timeinfo = localtime(&rawtime.tv_sec);
|
|
|
|
|
|
|
|
|
|
if (time_format == TIME) {
|
|
|
|
|
strftime(buffer, 64, "%H:%M:%S", timeinfo);
|
|
|
|
|
strcat(buffer, ".");
|
|
|
|
|
strftime(buffer, buffer_len, "%H:%M:%S.", timeinfo);
|
|
|
|
|
snprintf(us, 16, "%06ld", rawtime.tv_usec);
|
|
|
|
|
strcat(buffer, us);
|
|
|
|
|
uint32_t dest_len = strlen(buffer);
|
|
|
|
|
strncat(buffer, us, buffer_len - dest_len - 1);
|
|
|
|
|
} else {
|
|
|
|
|
usec_epoch = rawtime.tv_sec * 1000000 + rawtime.tv_usec;
|
|
|
|
|
snprintf(buffer, 64, "%ld", usec_epoch);
|
|
|
|
|
snprintf(buffer, buffer_len, "%ld", usec_epoch);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
now = time_src->get_time();
|
|
|
|
|
|
|
|
|
|
if (time_format == TIME) {
|
|
|
|
|
snprintf(buffer, 64, "%ld:%06u", now.full_secs, (uint32_t) (now.frac_secs * 1e6));
|
|
|
|
|
snprintf(buffer, buffer_len, "%ld:%06u", now.full_secs, (uint32_t)(now.frac_secs * 1e6));
|
|
|
|
|
} else {
|
|
|
|
|
usec_epoch = now.full_secs * 1000000 + (uint32_t) (now.frac_secs * 1e6);
|
|
|
|
|
snprintf(buffer, 64, "%ld", usec_epoch);
|
|
|
|
|
snprintf(buffer, buffer_len, "%ld", usec_epoch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::string(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string log_filter::hex_string(const uint8_t *hex, int size)
|
|
|
|
|