From 2ae531040f25443995b8dabe2fb45ce07e003770 Mon Sep 17 00:00:00 2001 From: Peter Schrammel Date: Mon, 12 Mar 2018 14:15:30 +0000 Subject: [PATCH 1/2] Add timestamp to JSON and XML messages --- src/util/ui_message.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util/ui_message.cpp b/src/util/ui_message.cpp index 1ba79f34db4..5aacaa2cfd9 100644 --- a/src/util/ui_message.cpp +++ b/src/util/ui_message.cpp @@ -244,6 +244,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'; @@ -263,6 +266,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 From 9374a1f049b7f1b537d3072e0f8bea36a7a9a5dd Mon Sep 17 00:00:00 2001 From: Peter Schrammel Date: Mon, 12 Mar 2018 14:16:36 +0000 Subject: [PATCH 2/2] Remove trailing whitespace from timestamp string --- src/util/timestamper.cpp | 5 ++--- src/util/ui_message.cpp | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/timestamper.cpp b/src/util/timestamper.cpp index 8ffb05ea1b3..f063e041cf5 100644 --- a/src/util/timestamper.cpp +++ b/src/util/timestamper.cpp @@ -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(); } @@ -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 diff --git a/src/util/ui_message.cpp b/src/util/ui_message.cpp index 5aacaa2cfd9..d725e701315 100644 --- a/src/util/ui_message.cpp +++ b/src/util/ui_message.cpp @@ -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;