21
21
22
22
ui_message_handlert::ui_message_handlert ()
23
23
: _ui(uit::PLAIN),
24
+ always_flush(false ),
24
25
time(timestampert::make(timestampert::clockt::NONE)),
25
26
out(std::cout),
26
27
json_stream(nullptr )
@@ -30,8 +31,10 @@ ui_message_handlert::ui_message_handlert()
30
31
ui_message_handlert::ui_message_handlert (
31
32
uit __ui,
32
33
const std::string &program,
34
+ bool always_flush,
33
35
timestampert::clockt clock_type)
34
36
: _ui(__ui),
37
+ always_flush(always_flush),
35
38
time(timestampert::make(clock_type)),
36
39
out(std::cout),
37
40
json_stream(nullptr )
@@ -79,6 +82,7 @@ ui_message_handlert::ui_message_handlert(
79
82
? uit::JSON_UI
80
83
: uit::PLAIN,
81
84
program,
85
+ cmdline.isset(" flush" ),
82
86
cmdline.isset(" timestamp" )
83
87
? cmdline.get_value(" timestamp" ) == "monotonic"
84
88
? timestampert::clockt::MONOTONIC
@@ -130,11 +134,13 @@ void ui_message_handlert::print(
130
134
{
131
135
case uit::PLAIN:
132
136
{
133
- console_message_handlert console_message_handler;
137
+ console_message_handlert console_message_handler (always_flush) ;
134
138
std::stringstream ss;
135
139
const std::string timestamp = time ->stamp ();
136
140
ss << timestamp << (timestamp.empty () ? " " : " " ) << message;
137
141
console_message_handler.print (level, ss.str ());
142
+ if (always_flush)
143
+ console_message_handler.flush (level);
138
144
}
139
145
break ;
140
146
@@ -144,6 +150,8 @@ void ui_message_handlert::print(
144
150
source_locationt location;
145
151
location.make_nil ();
146
152
print (level, message, -1 , location);
153
+ if (always_flush)
154
+ flush (level);
147
155
}
148
156
break ;
149
157
}
@@ -225,14 +233,15 @@ void ui_message_handlert::print(
225
233
std::string sequence_number_str=
226
234
sequence_number>=0 ?std::to_string (sequence_number):" " ;
227
235
228
- ui_msg (type, tmp_message, sequence_number_str, location);
236
+ ui_msg (level, type, tmp_message, sequence_number_str, location);
229
237
}
230
238
break ;
231
239
}
232
240
}
233
241
}
234
242
235
243
void ui_message_handlert::ui_msg (
244
+ const unsigned level,
236
245
const std::string &type,
237
246
const std::string &msg1,
238
247
const std::string &msg2,
@@ -244,7 +253,7 @@ void ui_message_handlert::ui_msg(
244
253
break ;
245
254
246
255
case uit::XML_UI:
247
- xml_ui_msg (type, msg1, msg2, location);
256
+ xml_ui_msg (level, type, msg1, msg2, location);
248
257
break ;
249
258
250
259
case uit::JSON_UI:
@@ -254,6 +263,7 @@ void ui_message_handlert::ui_msg(
254
263
}
255
264
256
265
void ui_message_handlert::xml_ui_msg (
266
+ const unsigned level,
257
267
const std::string &type,
258
268
const std::string &msg1,
259
269
const std::string &msg2,
@@ -274,6 +284,8 @@ void ui_message_handlert::xml_ui_msg(
274
284
275
285
out << result;
276
286
out << ' \n ' ;
287
+ if (always_flush)
288
+ flush (level);
277
289
}
278
290
279
291
void ui_message_handlert::json_ui_msg (
@@ -302,7 +314,7 @@ void ui_message_handlert::flush(unsigned level)
302
314
{
303
315
case uit::PLAIN:
304
316
{
305
- console_message_handlert console_message_handler;
317
+ console_message_handlert console_message_handler (always_flush) ;
306
318
console_message_handler.flush (level);
307
319
}
308
320
break ;
0 commit comments