Skip to content

Commit ebf24dd

Browse files
committed
std::emit_on_flush is not avaiable on libc++, use set_emit_on_sync instead.
1 parent 6b0e7bc commit ebf24dd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/lib/fcitx-utils/log.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ struct LogConfig {
4040
};
4141

4242
std::ostream *LogConfig::defaultLogStream = &std::cerr;
43-
thread_local std::osyncstream LogConfig::localLogStream{*defaultLogStream};
43+
thread_local std::osyncstream LogConfig::localLogStream = []() {
44+
std::osyncstream out(*LogConfig::defaultLogStream);
45+
out.rdbuf()->set_emit_on_sync(true);
46+
return out;
47+
}();
4448
bool LogConfig::showTimeDate = true;
4549

4650
bool validateLogLevel(std::underlying_type_t<LogLevel> l) {
@@ -198,14 +202,14 @@ std::ostream &Log::logStream() {
198202
auto *buf = LogConfig::defaultLogStream->rdbuf();
199203
if (LogConfig::localLogStream.get_wrapped() != buf) {
200204
LogConfig::localLogStream = std::osyncstream(buf);
205+
LogConfig::localLogStream.rdbuf()->set_emit_on_sync(true);
201206
}
202207
return LogConfig::localLogStream;
203208
}
204209

205210
LogMessageBuilder::LogMessageBuilder(std::ostream &out, LogLevel l,
206211
const char *filename, int lineNumber)
207212
: out_(out) {
208-
out << std::noemit_on_flush;
209213
switch (l) {
210214
case LogLevel::Fatal:
211215
out_ << "F";
@@ -247,7 +251,7 @@ LogMessageBuilder::LogMessageBuilder(std::ostream &out, LogLevel l,
247251
}
248252

249253
LogMessageBuilder::~LogMessageBuilder() {
250-
out_ << '\n' << std::emit_on_flush;
254+
out_ << '\n';
251255
out_.flush();
252256
}
253257

0 commit comments

Comments
 (0)