31 #include <QFileDialog>
33 #include <QDirIterator>
48 QDirIterator it(logdirectory_name, QStringList() <<
"*.log", QDir::Files);
51 QString filename = it.next();
52 printf(
"Loading log file %s ...\n", filename.toStdString().c_str());
59 std::string std_string_logfile = logfile_name.toStdString();
60 std::ifstream logfile(std_string_logfile.c_str());
62 for( std::string line; getline( logfile, line ); )
64 rosgraph_msgs::Log log;
65 unsigned found = std_string_logfile.find_last_of(
"/\\");
66 log.name = std_string_logfile.substr(found+1);
70 rosgraph_msgs::LogConstPtr log_ptr(
new rosgraph_msgs::Log(log));
81 char log_msg_fmt0[] =
"%d.%d %s [%[^:]:%u(%[^)]) [topics: %[^]]] %[^\n]s";
86 unsigned int line_num = 1;
93 int num_parsed = sscanf(line.c_str(),log_msg_fmt0,&secs, &nsecs, level, file, &line_num,
function, topics,
msg);
98 log->function =
function;
99 log->header.seq = seq;
102 log->header.stamp = stamp;
104 log->line = line_num;
109 char log_msg_fmt1[] =
"%d.%d %s [%[^:]:%u(%[^)])) [topics: %[^]]] %[^\n]s";
110 num_parsed = sscanf(line.c_str(), log_msg_fmt1, &secs, &nsecs, level, file, &line_num,
function, topics,
msg);
111 if (num_parsed == 8 )
115 log->function =
function;
116 log->header.seq = seq;
119 log->header.stamp = stamp;
121 log->line = line_num;
127 char log_msg_fmt2[] =
"[%[^]]][%[^]]] %d-%d-%d %d:%d:%d,%d: %[^\n]s";
136 struct tm * timeinfo;
138 num_parsed = sscanf(line.c_str(), log_msg_fmt2, name, level, &year, &month, &day, &hour, &minute, &secs, &msecs,
msg);
139 if (num_parsed == 10)
146 timeinfo = localtime ( &rawtime );
147 timeinfo->tm_year = year - 1900;
148 timeinfo->tm_mon = month - 1;
149 timeinfo->tm_mday = day;
150 timeinfo->tm_hour = hour;
151 timeinfo->tm_min = minute;
152 timeinfo->tm_sec = secs;
153 rawtime = mktime ( timeinfo );
155 nsecs = msecs * 1000000;
157 log->function =
function;
158 log->header.seq = seq;
161 log->header.stamp = stamp;
163 log->line = line_num;
169 char log_msg_fmt3[] =
"\x1b[%dm[ %[^]]] [%d.%d]: %[^\n\x1b]s";
173 num_parsed = sscanf(line.c_str(), log_msg_fmt3, &ansi_color, level, &secs, &nsecs,
msg);
181 log->function =
function;
182 log->header.seq = seq;
185 log->header.stamp = stamp;
187 log->line = line_num;
193 char log_msg_fmt4[] =
"\x1b[%dm[ %[^]]] [%d.%d, %d.%d]: %[^\n\x1b]";
197 num_parsed = sscanf(line.c_str(), log_msg_fmt4, &ansi_color, level, &secs, &nsecs, &secs2, &nsecs2,
msg);
205 log->function =
function;
206 log->header.seq = seq;
209 log->header.stamp = stamp;
211 log->line = line_num;
220 log->file = std::string(
"");
221 log->function = std::string(
"");
222 log->header.seq = seq;
225 log->header.stamp = stamp;
229 log->name = log->name +
"-unparsed";
240 if (level_str.compare(
"FATAL") == 0)
242 return rosgraph_msgs::Log::FATAL;
244 if (level_str.compare(
"ERROR") == 0)
246 return rosgraph_msgs::Log::ERROR;
248 if (level_str.compare(
"WARN") == 0)
250 return rosgraph_msgs::Log::WARN;
252 if (level_str.compare(
"INFO") == 0)
254 return rosgraph_msgs::Log::INFO;
256 return rosgraph_msgs::Log::DEBUG;
262 QString filename = QFileDialog::getOpenFileName(NULL,
263 tr(
"Open ROS Log File"),
265 tr(
"Log Files (*.log)"));
267 if (filename != NULL)
275 QString dirname = QFileDialog::getExistingDirectory(NULL,
276 tr(
"Open directory containing log files"),