/** * * \section COPYRIGHT * * Copyright 2013-2015 Software Radio Systems Limited * * \section LICENSE * * This file is part of the srsUE library. * * srsUE is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * srsUE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * A copy of the GNU Affero General Public License can be found in * the LICENSE file in the top-level directory of this distribution * and at http://www.gnu.org/licenses/. * */ #include #include #include #include #include #include #include #include #include #include #include #include "srslte/common/log_stdout.h" using namespace std; namespace srslte { void log_stdout::all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg) { std::stringstream ss; ss << now_time() << " "; ss << "[" < 0) printf("%s",args_msg); // Print directly to stdout va_end(args); free(args_msg); } void log_stdout::error(std::string message, ...) { if (level >= LOG_LEVEL_ERROR) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log(LOG_LEVEL_ERROR, tti, args_msg); va_end(args); free(args_msg); } } void log_stdout::warning(std::string message, ...) { if (level >= LOG_LEVEL_WARNING) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log(LOG_LEVEL_WARNING, tti, args_msg); va_end(args); free(args_msg); } } void log_stdout::info(std::string message, ...) { if (level >= LOG_LEVEL_INFO) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log(LOG_LEVEL_INFO, tti, args_msg); va_end(args); free(args_msg); } } void log_stdout::debug(std::string message, ...) { if (level >= LOG_LEVEL_DEBUG) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log(LOG_LEVEL_DEBUG, tti, args_msg); va_end(args); free(args_msg); } } void log_stdout::error_hex(uint8_t *hex, int size, std::string message, ...) { if (level >= LOG_LEVEL_ERROR) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log(LOG_LEVEL_ERROR, tti, args_msg, hex, size); va_end(args); free(args_msg); } } void log_stdout::warning_hex(uint8_t *hex, int size, std::string message, ...) { if (level >= LOG_LEVEL_WARNING) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log(LOG_LEVEL_WARNING, tti, args_msg, hex, size); va_end(args); free(args_msg); } } void log_stdout::info_hex(uint8_t *hex, int size, std::string message, ...) { if (level >= LOG_LEVEL_INFO) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log(LOG_LEVEL_INFO, tti, args_msg, hex, size); va_end(args); free(args_msg); } } void log_stdout::debug_hex(uint8_t *hex, int size, std::string message, ...) { if (level >= LOG_LEVEL_DEBUG) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log(LOG_LEVEL_DEBUG, tti, args_msg, hex, size); va_end(args); free(args_msg); } } void log_stdout::error_line(std::string file, int line, std::string message, ...) { if (level >= LOG_LEVEL_ERROR) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log_line(LOG_LEVEL_ERROR, tti, file, line, args_msg); va_end(args); free(args_msg); } } void log_stdout::warning_line(std::string file, int line, std::string message, ...) { if (level >= LOG_LEVEL_WARNING) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log_line(LOG_LEVEL_WARNING, tti, file, line, args_msg); va_end(args); free(args_msg); } } void log_stdout::info_line(std::string file, int line, std::string message, ...) { if (level >= LOG_LEVEL_INFO) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log_line(LOG_LEVEL_INFO, tti, file, line, args_msg); va_end(args); free(args_msg); } } void log_stdout::debug_line(std::string file, int line, std::string message, ...) { if (level >= LOG_LEVEL_DEBUG) { char *args_msg; va_list args; va_start(args, message); if(vasprintf(&args_msg, message.c_str(), args) > 0) all_log_line(LOG_LEVEL_DEBUG, tti, file, line, args_msg); va_end(args); free(args_msg); } } std::string log_stdout::now_time() { struct timeval rawtime; struct tm * timeinfo; char buffer[64]; char us[16]; gettimeofday(&rawtime, NULL); timeinfo = localtime(&rawtime.tv_sec); strftime(buffer,64,"%H:%M:%S",timeinfo); strcat(buffer,"."); snprintf(us,16,"%ld",rawtime.tv_usec); strcat(buffer,us); return std::string(buffer); } std::string log_stdout::hex_string(uint8_t *hex, int size) { std::stringstream ss; int c = 0; ss << std::hex << std::setfill('0'); if(hex_limit >= 0) { size = (size > hex_limit) ? hex_limit : size; } while(c < size) { ss << " " << std::setw(4) << static_cast(c) << ": "; int tmp = (size-c < 16) ? size-c : 16; for(int i=0;i(hex[c++]) << " "; } ss << "\n"; } return ss.str(); } }