Skip to content

Commit

Permalink
Make test logs readable in CLion
Browse files Browse the repository at this point in the history
CLion's test runner seems to treat stderr and std::cerr differently!
- Output to stderr is written while the test is running.
- Output to cerr is suppressed while the test is running, then dumped
  at the end.
LogDomain::defaultCallback() happens to write the timestamp and
domain to cerr, but the message itself to stderr.
I fixed it to write everything to cerr.
  • Loading branch information
snej committed Sep 18, 2024
1 parent 57962fe commit b478d55
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions LiteCore/Support/Logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,12 @@ namespace litecore {
ANDROID_LOG_ERROR};
__android_log_vprint(androidLevels[(int)level], tag.c_str(), fmt, args);
#else
auto name = domain.name();
char* cstr = nullptr;
if ( vasprintf(&cstr, fmt, args) < 0 ) throw bad_alloc();
LogDecoder::writeTimestamp(LogDecoder::now(), cerr);
LogDecoder::writeHeader(kLevels[(int)level], name, cerr);
vfprintf(stderr, fmt, args);
fputc('\n', stderr);
LogDecoder::writeHeader(kLevels[(int)level], domain.name(), cerr);
cerr << cstr << endl;
free(cstr);
#endif
}

Expand Down

0 comments on commit b478d55

Please sign in to comment.