Skip to content

Commit

Permalink
Add: Added support for log files of the format "Example: 1724314618.1…
Browse files Browse the repository at this point in the history
…46484723 [INFO] [namespace.Node::Fuction]: The actual log msg".

Refactor: Removed nested if's
  • Loading branch information
rasmusan committed Sep 3, 2024
1 parent da2507c commit 0c4de20
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions src/rosout_log_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,72 +102,72 @@ namespace swri_console
log->level = level_string_to_level_type(std::string(level));
log->line = line_num;
log->msg = msg;
return 0;
}

// try another format
char log_msg_fmt1[] = "%d.%d %s [%[^:]:%u(%[^)])) [topics: %[^]]] %[^\n]s";
num_parsed = sscanf(line.c_str(), log_msg_fmt1, &secs, &nsecs, level, file, &line_num, function, topics, msg);
if (num_parsed == 8) {
// Populate new log message
log->file = file;
log->function = function;
// log->header.seq = seq;
// stamp.sec = secs;
// stamp.nsec = nsecs;
stamp = rclcpp::Time(secs, nsecs);
log->stamp = stamp;
log->level = level_string_to_level_type(std::string(level));
log->line = line_num;
log->msg = msg;
return 0;
}

// try another format
// Example: [rospy.registration][INFO] 2017-11-30 08:11:39,231: registering subscriber topic [/tf] type [tf2_msgs/TFMessage] with master
char log_msg_fmt2[] = "[%[^]]][%[^]]] %d-%d-%d %d:%d:%d,%d: %[^\n]s";
int year;
int month;
int day;
int hour;
int minute;
int msecs;
char name[1024];
time_t rawtime;
struct tm * timeinfo;

num_parsed = sscanf(line.c_str(), log_msg_fmt2, name, level, &year, &month, &day, &hour, &minute, &secs, &msecs, msg);
if (num_parsed == 10) {
// Populate new log message
file[0] = 0;
function[0] = 0;
line_num = 0;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
timeinfo->tm_year = year - 1900;
timeinfo->tm_mon = month - 1;
timeinfo->tm_mday = day;
timeinfo->tm_hour = hour;
timeinfo->tm_min = minute;
timeinfo->tm_sec = secs;
rawtime = mktime ( timeinfo );
secs = rawtime;
nsecs = msecs * 1000000;
log->file = file;
log->function = function;
// log->header.seq = seq;
// stamp.sec = secs;
// stamp.nsec = nsecs;
stamp = rclcpp::Time(secs, nsecs);
log->stamp = stamp;
log->level = level_string_to_level_type(std::string(level));
log->line = line_num;
log->msg = msg;
return 0;
}
else // try another format
{
char log_msg_fmt1[] = "%d.%d %s [%[^:]:%u(%[^)])) [topics: %[^]]] %[^\n]s";
num_parsed = sscanf(line.c_str(), log_msg_fmt1, &secs, &nsecs, level, file, &line_num, function, topics, msg);
if (num_parsed == 8 )
{
// Populate new log message
log->file = file;
log->function = function;
// log->header.seq = seq;
// stamp.sec = secs;
// stamp.nsec = nsecs;
stamp = rclcpp::Time(secs, nsecs);
log->stamp = stamp;
log->level = level_string_to_level_type(std::string(level));
log->line = line_num;
log->msg = msg;
}
else // try another format
{
// Example: [rospy.registration][INFO] 2017-11-30 08:11:39,231: registering subscriber topic [/tf] type [tf2_msgs/TFMessage] with master
char log_msg_fmt2[] = "[%[^]]][%[^]]] %d-%d-%d %d:%d:%d,%d: %[^\n]s";
int year;
int month;
int day;
int hour;
int minute;
int msecs;
char name[1024];
time_t rawtime;
struct tm * timeinfo;

num_parsed = sscanf(line.c_str(), log_msg_fmt2, name, level, &year, &month, &day, &hour, &minute, &secs, &msecs, msg);
if (num_parsed == 10)
{
// Populate new log message
file[0] = 0;
function[0] = 0;
line_num = 0;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
timeinfo->tm_year = year - 1900;
timeinfo->tm_mon = month - 1;
timeinfo->tm_mday = day;
timeinfo->tm_hour = hour;
timeinfo->tm_min = minute;
timeinfo->tm_sec = secs;
rawtime = mktime ( timeinfo );
secs = rawtime;
nsecs = msecs * 1000000;
log->file = file;
log->function = function;
// log->header.seq = seq;
// stamp.sec = secs;
// stamp.nsec = nsecs;
stamp = rclcpp::Time(secs, nsecs);
log->stamp = stamp;
log->level = level_string_to_level_type(std::string(level));
log->line = line_num;
log->msg = msg;
}
else
{
// Example: [ INFO] [1512051098.518631473]: Read parameter lower_cost_threshold = 0.000000
char log_msg_fmt3[] = "\x1b[%dm[ %[^]]] [%d.%d]: %[^\n\x1b]s";
// Example: [ INFO] [1512051098.518631473]: Read parameter lower_cost_threshold = 0.000000
char log_msg_fmt3[] = "\x1b[%dm[ %[^]]] [%d.%d]: %[^\n\x1b]s";
// char log_msg_fmt3[] = "\x1b[%dm[ %[^]]] [%d.%d]]%[^\n]";
int ansi_color;
msg[0] = 0;
Expand Down

0 comments on commit 0c4de20

Please sign in to comment.