20bool LoggerEngine::export_log_to_text_file (std::string filename, std::string portname)
22 if (log_updater ==
nullptr) {
25 if (filename.size() == 0) {
29 log_updater->mutex.lock();
30 std::list<LogEntry>::iterator it;
31 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
33 if (it->logInfo.port_complete == portname)
36 file1.open(filename.c_str());
37 if (file1.is_open() ==
false) {log_updater->mutex.unlock();
return false;}
38 std::vector<MessageEntry>::iterator it1;
39 for (it1 = it->entry_list.begin(); it1 != it->entry_list.end(); it1++)
41 file1 << it1->yarprun_timestamp <<
" " << it1->local_timestamp <<
" <" << it1->level.toString() <<
"> " << it1->text <<
'\n';
46 log_updater->mutex.unlock();
59 file <<
"NULL-DATA" <<
'\n';
70 if (data ==
"NULL-DATA") data=
"";
83 if (log_updater ==
nullptr) {
86 if (filename.size() == 0) {
90 const int LOGFILE_VERSION_1 = 1;
93 file1.open(filename.c_str());
94 if (file1.is_open() ==
false) {
98 bool wasRunning = log_updater->isRunning();
102 std::list<LogEntry>::iterator it;
104 SaveToFile(file1, log_updater->log_list.size());
105 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
113 SaveToFile(file1, it->logInfo.get_number_of_traces());
114 SaveToFile(file1, it->logInfo.get_number_of_debugs());
115 SaveToFile(file1, it->logInfo.get_number_of_infos());
116 SaveToFile(file1, it->logInfo.get_number_of_warnings());
117 SaveToFile(file1, it->logInfo.get_number_of_errors());
118 SaveToFile(file1, it->logInfo.get_number_of_fatals());
122 std::vector<MessageEntry>::iterator it1;
123 for (it1 = it->entry_list.begin(); it1 != it->entry_list.end(); it1++)
129 for (
char s : it1->text)
138 log_updater->start();
143std::streamoff
get_tag(std::ifstream& file,
const char* tag)
145 std::streamoff pos=file.tellg();
146 int tag_size=strlen(tag);
147 char* buff =
new char[tag_size+2];
148 for (
int i = 0; i < tag_size + 2; i++) {
151 std::streamoff off=0;
155 file.read(buff,tag_size);
156 if (file.good()==
false)
161 if (strcmp(buff, tag) == 0) {
172 int end_string_size=strlen(
end_string.c_str());
174 if (log_updater ==
nullptr) {
177 if (filename.size() == 0) {
181 const int LOGFILE_VERSION_1 = 1;
184 file1.open(filename.c_str(),std::ifstream::binary);
185 if (file1.is_open() ==
false) {
189 int log_file_version;
190 bool wasRunning = log_updater->isRunning();
194 file1 >> log_file_version;
195 if (log_file_version == LOGFILE_VERSION_1)
197 unsigned int size_log_list;
200 log_updater->log_list.clear();
201 for (
unsigned int i=0; i< size_log_list; i++)
218 unsigned int size_entry_list;
220 for (
size_t j=0; j< size_entry_list; j++)
225 unsigned int tmp_level;
232 if (start_p < 0 || end_p < 0 || end_p - start_p + start_string_size <= 0) {
235 char *buff =
new char[(
unsigned int)(end_p-start_p+start_string_size)];
237 file1.seekg(start_p+start_string_size);
238 if (end_p-start_p-start_string_size!=1)
240 file1.get(buff,end_p-start_p-start_string_size);
246 file1.seekg(end_p+end_string_size);
251 log_updater->log_list.push_back(l_tmp);
256 log_updater->start();
std::streamoff get_tag(std::ifstream &file, const char *tag)
void SaveToFile(std::ofstream &file, unsigned int data)
void LoadFromFile(std::ifstream &file, std::string &data)
std::string port_complete
yarp::yarpLogger::LogEntryInfo logInfo
std::vector< MessageEntry > entry_list
void setLevel(LogLevelEnum level)
bool load_all_logs_from_file(std::string filename)
bool save_all_logs_to_file(std::string filename)
An interface to the operating system, including Port based communication.
std::string yarprun_timestamp
std::string local_timestamp