Skip to content

JSON and XML message timestamps #1927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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