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
@@ -274,6 +280,8 @@ void ui_message_handlert::xml_ui_msg(
274
280
275
281
out << result;
276
282
out << ' \n ' ;
283
+ if (always_flush)
284
+ flush (1 );
277
285
}
278
286
279
287
void ui_message_handlert::json_ui_msg (
@@ -299,6 +307,8 @@ void ui_message_handlert::json_ui_msg(
299
307
// The first entry is generated in the constructor and does not have
300
308
// a trailing comma.
301
309
std::cout << " ,\n " << result;
310
+ if (always_flush)
311
+ flush (1 );
302
312
}
303
313
304
314
void ui_message_handlert::flush (unsigned level)
@@ -307,7 +317,7 @@ void ui_message_handlert::flush(unsigned level)
307
317
{
308
318
case uit::PLAIN:
309
319
{
310
- console_message_handlert console_message_handler;
320
+ console_message_handlert console_message_handler (always_flush) ;
311
321
console_message_handler.flush (level);
312
322
}
313
323
break ;
0 commit comments