Added rotating log to srsUE and srsENB

master
Ismael Gomez 7 years ago
parent 1f5ac41b37
commit 3be48c40c8

@ -51,7 +51,7 @@ public:
logger_file();
logger_file(std::string file);
~logger_file();
void init(std::string file);
void init(std::string file, int max_length = -1);
// Implementation of log_out
void log(str_ptr msg);
void log(const char *msg);
@ -60,6 +60,9 @@ private:
void run_thread();
void flush();
uint32_t name_idx;
int64_t max_length;
int64_t cur_length;
FILE* logfile;
bool inited;
bool not_done;

@ -48,16 +48,18 @@ logger_file::~logger_file() {
}
}
void logger_file::init(std::string file) {
void logger_file::init(std::string file, int max_length) {
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&not_empty, NULL);
pthread_cond_init(&not_full, NULL);
this->max_length = max_length*1024;
name_idx = 0;
filename = file;
logfile = fopen(filename.c_str(), "w");
if(logfile==NULL) {
printf("Error: could not create log file, no messages will be logged!\n");
}
start();
start(-2);
inited = true;
}
@ -74,17 +76,33 @@ void logger_file::log(str_ptr msg) {
void logger_file::run_thread() {
while(not_done) {
pthread_mutex_lock(&mutex);
pthread_mutex_lock(&mutex);
while(buffer.empty()) {
pthread_cond_wait(&not_empty, &mutex);
}
str_ptr s = buffer.front();
pthread_cond_signal(&not_full);
int n = 0;
if(logfile)
fprintf(logfile, "%s", s->c_str());
n = fprintf(logfile, "%s", s->c_str());
delete s;
buffer.pop_front();
pthread_mutex_unlock(&mutex);
if (n > 0) {
cur_length += (int64_t) n;
if (cur_length >= max_length && max_length > 0) {
fclose(logfile);
name_idx++;
char numstr[21]; // enough to hold all numbers up to 64-bits
sprintf(numstr, ".%d", name_idx);
string newfilename = filename + numstr ;
logfile = fopen(newfilename.c_str(), "w");
if(logfile==NULL) {
printf("Error: could not create log file, no messages will be logged!\n");
}
cur_length = 0;
}
}
}
}

@ -102,11 +102,14 @@ filename = /tmp/enb.pcap
#
# filename: File path to use for log output. Can be set to stdout
# to print logs to standard output
# file_max_size: Maximum file size (in kilobytes). When passed, multiple files are created.
# If set to negative, a single log file will be created.
#####################################################################
[log]
all_level = info
all_hex_limit = 32
filename = /tmp/enb.log
file_max_size = -1
[gui]
enable = false

@ -111,6 +111,7 @@ typedef struct {
int gtpu_hex_limit;
int s1ap_hex_limit;
int all_hex_limit;
int file_max_size;
std::string filename;
}log_args_t;

@ -72,7 +72,7 @@ bool enb::init(all_args_t *args_)
if (!args->log.filename.compare("stdout")) {
logger = &logger_stdout;
} else {
logger_file.init(args->log.filename);
logger_file.init(args->log.filename, args->log.file_max_size);
logger_file.log("\n\n");
logger = &logger_file;
}

@ -120,6 +120,7 @@ void parse_args(all_args_t *args, int argc, char* argv[]) {
("log.all_hex_limit", bpo::value<int>(&args->log.all_hex_limit)->default_value(32), "ALL log hex dump limit")
("log.filename", bpo::value<string>(&args->log.filename)->default_value("/tmp/ue.log"),"Log filename")
("log.file_max_size", bpo::value<int>(&args->log.file_max_size)->default_value(-1), "Maximum file size (in kilobytes). When passed, multiple files are created. Default -1 (single file)")
/* MCS section */
("scheduler.pdsch_mcs",

@ -99,6 +99,7 @@ typedef struct {
int nas_hex_limit;
int usim_hex_limit;
int all_hex_limit;
int file_max_size;
std::string filename;
}log_args_t;

@ -120,6 +120,7 @@ void parse_args(all_args_t *args, int argc, char *argv[]) {
("log.all_hex_limit", bpo::value<int>(&args->log.all_hex_limit)->default_value(32), "ALL log hex dump limit")
("log.filename", bpo::value<string>(&args->log.filename)->default_value("/tmp/ue.log"), "Log filename")
("log.file_max_size", bpo::value<int>(&args->log.file_max_size)->default_value(-1), "Maximum file size (in kilobytes). When passed, multiple files are created. Default -1 (single file)")
("usim.algo", bpo::value<string>(&args->usim.algo), "USIM authentication algorithm")
("usim.op", bpo::value<string>(&args->usim.op), "USIM operator variant")

@ -55,7 +55,7 @@ bool ue::init(all_args_t *args_)
if (!args->log.filename.compare("stdout")) {
logger = &logger_stdout;
} else {
logger_file.init(args->log.filename);
logger_file.init(args->log.filename, args->log.file_max_size);
logger_file.log("\n\n");
logger_file.log(get_build_string().c_str());
logger = &logger_file;

@ -70,12 +70,15 @@ nas_filename = /tmp/nas.pcap
#
# filename: File path to use for log output. Can be set to stdout
# to print logs to standard output
# file_max_size: Maximum file size (in kilobytes). When passed, multiple files are created.
# If set to negative, a single log file will be created.
#####################################################################
[log]
all_level = info
phy_lib_level = none
all_hex_limit = 32
filename = /tmp/ue.log
file_max_size = -1
#####################################################################
# USIM configuration

Loading…
Cancel
Save