Skip to content

Commit 1abbaff

Browse files
authored
Merge pull request #1927 from peterschrammel/json-xml-timestamps
JSON and XML message timestamps
2 parents 1e7f2bc + 9374a1f commit 1abbaff

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/util/timestamper.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ std::string monotonic_timestampert::stamp() const
4747
std::lldiv_t divmod = lldiv(cnt, 1000000);
4848

4949
std::stringstream ss;
50-
ss << divmod.quot << "." << std::setfill('0') << std::setw(6) << divmod.rem
51-
<< " ";
50+
ss << divmod.quot << "." << std::setfill('0') << std::setw(6) << divmod.rem;
5251
return ss.str();
5352
}
5453

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

6867
std::stringstream ss;
6968
ss << std::put_time(&local, WALL_FORMAT) << std::setfill('0') << std::setw(6)
70-
<< u_seconds << " ";
69+
<< u_seconds;
7170
return ss.str();
7271
}
7372
#endif

src/util/ui_message.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ void ui_message_handlert::print(
110110
{
111111
console_message_handlert console_message_handler;
112112
std::stringstream ss;
113-
ss << time->stamp() << message;
113+
const std::string timestamp = time->stamp();
114+
ss << timestamp << (timestamp.empty() ? "" : " ") << message;
114115
console_message_handler.print(level, ss.str());
115116
}
116117
break;
@@ -244,6 +245,9 @@ void ui_message_handlert::xml_ui_msg(
244245

245246
result.new_element("text").data=msg1;
246247
result.set_attribute("type", type);
248+
const std::string timestamp = time->stamp();
249+
if(!timestamp.empty())
250+
result.set_attribute("timestamp", timestamp);
247251

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

264268
result["messageType"] = json_stringt(type);
265269
result["messageText"] = json_stringt(msg1);
270+
const std::string timestamp = time->stamp();
271+
if(!timestamp.empty())
272+
result["timestamp"] = json_stringt(timestamp);
266273

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

0 commit comments

Comments
 (0)