mirror of https://github.com/pvnis/srsRAN_4G.git
Merge branch 'next' of https://github.com/softwareradiosystems/srslte into next
commit
769c2c1f6b
@ -1,82 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* \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/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: log_stout.h
|
||||
*
|
||||
* Description: Logging service through standard output. Inherits log interface
|
||||
*
|
||||
* Reference:
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef LOGSTDOUT_H
|
||||
#define LOGSTDOUT_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
#include "srslte/common/log.h"
|
||||
|
||||
namespace srslte {
|
||||
|
||||
class log_stdout : public log
|
||||
{
|
||||
public:
|
||||
|
||||
log_stdout(std::string service_name_) : log(service_name_) { }
|
||||
|
||||
void console(std::string message, ...);
|
||||
void error(std::string message, ...);
|
||||
void warning(std::string message, ...);
|
||||
void info(std::string message, ...);
|
||||
void debug(std::string message, ...);
|
||||
|
||||
// Same with hex dump
|
||||
void error_hex(uint8_t *hex, int size, std::string message, ...);
|
||||
void warning_hex(uint8_t *hex, int size, std::string message, ...);
|
||||
void info_hex(uint8_t *hex, int size, std::string message, ...);
|
||||
void debug_hex(uint8_t *hex, int size, std::string message, ...);
|
||||
|
||||
// Same with line and file info
|
||||
void error_line(std::string file, int line, std::string message, ...);
|
||||
void warning_line(std::string file, int line, std::string message, ...);
|
||||
void info_line(std::string file, int line, std::string message, ...);
|
||||
void debug_line(std::string file, int line, std::string message, ...);
|
||||
|
||||
private:
|
||||
void printlog(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string file, int line, std::string message, va_list args);
|
||||
void printlog(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string message, va_list args);
|
||||
|
||||
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg);
|
||||
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg, uint8_t *hex, int size);
|
||||
void all_log_line(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string file, int line, char *msg);
|
||||
std::string now_time();
|
||||
std::string hex_string(uint8_t *hex, int size);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,76 @@
|
||||
/**
|
||||
*
|
||||
* \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/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: logger_file.h
|
||||
* Description: Common log object. Maintains a queue of log messages
|
||||
* and runs a thread to read messages and write to file.
|
||||
* Multiple producers, single consumer. If full, producers
|
||||
* increase queue size. If empty, consumer blocks.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef LOGGER_FILE_H
|
||||
#define LOGGER_FILE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include "srslte/common/logger.h"
|
||||
#include "srslte/common/threads.h"
|
||||
|
||||
namespace srslte {
|
||||
|
||||
typedef std::string* str_ptr;
|
||||
|
||||
class logger_file : public thread, public logger
|
||||
{
|
||||
public:
|
||||
logger_file();
|
||||
logger_file(std::string file);
|
||||
~logger_file();
|
||||
void init(std::string file);
|
||||
// Implementation of log_out
|
||||
void log(str_ptr msg);
|
||||
void log(const char *msg);
|
||||
|
||||
private:
|
||||
void run_thread();
|
||||
void flush();
|
||||
|
||||
FILE* logfile;
|
||||
bool inited;
|
||||
bool not_done;
|
||||
std::string filename;
|
||||
pthread_cond_t not_empty;
|
||||
pthread_cond_t not_full;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_t thread;
|
||||
std::deque<str_ptr> buffer;
|
||||
};
|
||||
|
||||
} // namespace srsue
|
||||
|
||||
#endif // LOGGER_H
|
@ -0,0 +1,51 @@
|
||||
/**
|
||||
*
|
||||
* \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/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: logger_stdout.h
|
||||
* Description: Interface for logging output
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef LOGGER_STDOUT_H
|
||||
#define LOGGER_STDOUT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "srslte/common/logger.h"
|
||||
|
||||
namespace srslte {
|
||||
|
||||
class logger_stdout : public logger
|
||||
{
|
||||
public:
|
||||
void log(std::string *msg) {
|
||||
fprintf(stdout, "%s", msg->c_str());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace srslte
|
||||
|
||||
#endif // LOGGER_H
|
@ -1,290 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* \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 <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#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 << "[" <<get_service_name() << "] ";
|
||||
ss << log_level_text[level] << " ";
|
||||
ss << "[" << std::setfill('0') << std::setw(5) << tti << "] ";
|
||||
ss << msg;
|
||||
|
||||
cout << ss.str();
|
||||
}
|
||||
|
||||
void log_stdout::all_log(srslte::LOG_LEVEL_ENUM level,
|
||||
uint32_t tti,
|
||||
char *msg,
|
||||
uint8_t *hex,
|
||||
int size)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << now_time() << " ";
|
||||
ss << "[" <<get_service_name() << "] ";
|
||||
ss << log_level_text[level] << " ";
|
||||
ss << "[" << std::setfill('0') << std::setw(5) << tti << "] ";
|
||||
ss << msg << std::endl;
|
||||
ss << hex_string(hex, size);
|
||||
|
||||
cout << ss.str();
|
||||
}
|
||||
|
||||
void log_stdout::all_log_line(srslte::LOG_LEVEL_ENUM level,
|
||||
uint32_t tti,
|
||||
std::string file,
|
||||
int line,
|
||||
char *msg)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << now_time() << " ";
|
||||
ss << "[" <<get_service_name() << "] ";
|
||||
ss << log_level_text[level] << " ";
|
||||
ss << "[" << std::setfill('0') << std::setw(5) << tti << "] ";
|
||||
ss << msg;
|
||||
|
||||
cout << ss.str();
|
||||
}
|
||||
|
||||
void log_stdout::console(std::string message, ...) {
|
||||
char *args_msg;
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
if(vasprintf(&args_msg, message.c_str(), args) > 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<unsigned>(c) << ": ";
|
||||
int tmp = (size-c < 16) ? size-c : 16;
|
||||
for(int i=0;i<tmp;i++) {
|
||||
ss << std::setw(2) << static_cast<unsigned>(hex[c++]) << " ";
|
||||
}
|
||||
ss << "\n";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue