Skip to content

Commit

Permalink
Merge pull request diffblue#1927 from peterschrammel/json-xml-timestamps
Browse files Browse the repository at this point in the history
JSON and XML message timestamps
  • Loading branch information
tautschnig authored Mar 12, 2018
2 parents 1e7f2bc + 9374a1f commit 1abbaff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/util/timestamper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ std::string monotonic_timestampert::stamp() const
std::lldiv_t divmod = lldiv(cnt, 1000000);

std::stringstream ss;
ss << divmod.quot << "." << std::setfill('0') << std::setw(6) << divmod.rem
<< " ";
ss << divmod.quot << "." << std::setfill('0') << std::setw(6) << divmod.rem;
return ss.str();
}

Expand All @@ -67,7 +66,7 @@ std::string wall_clock_timestampert::stamp() const

std::stringstream ss;
ss << std::put_time(&local, WALL_FORMAT) << std::setfill('0') << std::setw(6)
<< u_seconds << " ";
<< u_seconds;
return ss.str();
}
#endif
9 changes: 8 additions & 1 deletion src/util/ui_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ void ui_message_handlert::print(
{
console_message_handlert console_message_handler;
std::stringstream ss;
ss << time->stamp() << message;
const std::string timestamp = time->stamp();
ss << timestamp << (timestamp.empty() ? "" : " ") << message;
console_message_handler.print(level, ss.str());
}
break;
Expand Down Expand Up @@ -244,6 +245,9 @@ void ui_message_handlert::xml_ui_msg(

result.new_element("text").data=msg1;
result.set_attribute("type", type);
const std::string timestamp = time->stamp();
if(!timestamp.empty())
result.set_attribute("timestamp", timestamp);

std::cout << result;
std::cout << '\n';
Expand All @@ -263,6 +267,9 @@ void ui_message_handlert::json_ui_msg(

result["messageType"] = json_stringt(type);
result["messageText"] = json_stringt(msg1);
const std::string timestamp = time->stamp();
if(!timestamp.empty())
result["timestamp"] = json_stringt(timestamp);

// By convention a leading comma is created by every new array entry.
// The first entry is generated in the constructor and does not have
Expand Down

0 comments on commit 1abbaff

Please sign in to comment.