Improve dump of short MemoryLog.

This commit is contained in:
levlam 2022-09-18 01:17:09 +03:00
parent c35bbf1bd2
commit c20f0c3d97
1 changed files with 8 additions and 1 deletions

View File

@ -80,8 +80,15 @@ static td::MemoryLog<1 << 20> memory_log;
void print_log() {
auto buf = memory_log.get_buffer();
auto pos = memory_log.get_pos();
size_t tail_length = buf.size() - pos;
while (tail_length > 0 && buf[pos + tail_length - 1] == ' ') {
tail_length--;
}
if (tail_length + 100 >= buf.size() - pos) {
tail_length = buf.size() - pos;
}
td::signal_safe_write("------- Log dump -------\n");
td::signal_safe_write(buf.substr(pos), false);
td::signal_safe_write(buf.substr(pos, tail_length), false);
td::signal_safe_write(buf.substr(0, pos), false);
td::signal_safe_write("\n", false);
td::signal_safe_write("------------------------\n");