Remove unconditional block in logging.
Remove unconditional block in logging. This was done so the previous commit shows an actual useful diff.
This commit is contained in:
parent
458dbba4ae
commit
6bd96a5091
|
@ -152,88 +152,85 @@ class Logger {
|
||||||
next_range.last(), last_sequence);
|
next_range.last(), last_sequence);
|
||||||
|
|
||||||
size_t read_count = 0;
|
size_t read_count = 0;
|
||||||
|
auto available_range = next_range;
|
||||||
|
auto available_count = available_range.size();
|
||||||
|
|
||||||
{
|
rb.set_write_offset(BlockOffset(available_range.end()));
|
||||||
auto available_range = next_range;
|
|
||||||
auto available_count = available_range.size();
|
|
||||||
|
|
||||||
rb.set_write_offset(BlockOffset(available_range.end()));
|
bool terminate = false;
|
||||||
|
for (size_t i = available_range.first(); i != available_range.end();) {
|
||||||
|
rb.set_read_offset(BlockOffset(i));
|
||||||
|
|
||||||
bool terminate = false;
|
LogLine line;
|
||||||
for (size_t i = available_range.first(); i != available_range.end();) {
|
rb.Read(&line, sizeof(line));
|
||||||
rb.set_read_offset(BlockOffset(i));
|
|
||||||
|
|
||||||
LogLine line;
|
auto needed_count = BlockCount(sizeof(LogLine) + line.buffer_length);
|
||||||
rb.Read(&line, sizeof(line));
|
if (read_count + needed_count > available_count) {
|
||||||
|
// More blocks are needed for a complete line.
|
||||||
|
desired_count = needed_count;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// Enough blocks to read this log line, advance by that many.
|
||||||
|
read_count += needed_count;
|
||||||
|
i += needed_count;
|
||||||
|
|
||||||
auto needed_count = BlockCount(sizeof(LogLine) + line.buffer_length);
|
if (line.prefix_char) {
|
||||||
if (read_count + needed_count > available_count) {
|
char prefix[] = {
|
||||||
// More blocks are needed for a complete line.
|
line.prefix_char,
|
||||||
desired_count = needed_count;
|
'>',
|
||||||
break;
|
' ',
|
||||||
} else {
|
'?', // Thread ID gets placed here (8 chars).
|
||||||
// Enough blocks to read this log line, advance by that many.
|
'?',
|
||||||
read_count += needed_count;
|
'?',
|
||||||
i += needed_count;
|
'?',
|
||||||
|
'?',
|
||||||
|
'?',
|
||||||
|
'?',
|
||||||
|
'?',
|
||||||
|
' ',
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
fmt::format_to_n(prefix + 3, sizeof(prefix) - 3, "{:08X}",
|
||||||
|
line.thread_id);
|
||||||
|
Write(prefix, sizeof(prefix) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (line.prefix_char) {
|
if (line.buffer_length) {
|
||||||
char prefix[] = {
|
// Get access to the line data - which may be split in the ring
|
||||||
line.prefix_char,
|
// buffer - and write it out in parts.
|
||||||
'>',
|
auto line_range = rb.BeginRead(line.buffer_length);
|
||||||
' ',
|
Write(reinterpret_cast<const char*>(line_range.first),
|
||||||
'?', // Thread ID gets placed here (8 chars).
|
line_range.first_length);
|
||||||
'?',
|
if (line_range.second_length) {
|
||||||
'?',
|
Write(reinterpret_cast<const char*>(line_range.second),
|
||||||
'?',
|
line_range.second_length);
|
||||||
'?',
|
|
||||||
'?',
|
|
||||||
'?',
|
|
||||||
'?',
|
|
||||||
' ',
|
|
||||||
0,
|
|
||||||
};
|
|
||||||
fmt::format_to_n(prefix + 3, sizeof(prefix) - 3, "{:08X}",
|
|
||||||
line.thread_id);
|
|
||||||
Write(prefix, sizeof(prefix) - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.buffer_length) {
|
// Always ensure there is a newline.
|
||||||
// Get access to the line data - which may be split in the ring
|
char last_char =
|
||||||
// buffer - and write it out in parts.
|
line_range.second
|
||||||
auto line_range = rb.BeginRead(line.buffer_length);
|
? line_range.second[line_range.second_length - 1]
|
||||||
Write(reinterpret_cast<const char*>(line_range.first),
|
: line_range.first[line_range.first_length - 1];
|
||||||
line_range.first_length);
|
if (last_char != '\n') {
|
||||||
if (line_range.second_length) {
|
|
||||||
Write(reinterpret_cast<const char*>(line_range.second),
|
|
||||||
line_range.second_length);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always ensure there is a newline.
|
|
||||||
char last_char =
|
|
||||||
line_range.second
|
|
||||||
? line_range.second[line_range.second_length - 1]
|
|
||||||
: line_range.first[line_range.first_length - 1];
|
|
||||||
if (last_char != '\n') {
|
|
||||||
const char suffix[1] = {'\n'};
|
|
||||||
Write(suffix, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
rb.EndRead(std::move(line_range));
|
|
||||||
} else {
|
|
||||||
// Always ensure there is a newline.
|
|
||||||
const char suffix[1] = {'\n'};
|
const char suffix[1] = {'\n'};
|
||||||
Write(suffix, 1);
|
Write(suffix, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.terminate) {
|
rb.EndRead(std::move(line_range));
|
||||||
terminate = true;
|
} else {
|
||||||
}
|
// Always ensure there is a newline.
|
||||||
|
const char suffix[1] = {'\n'};
|
||||||
|
Write(suffix, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.terminate) {
|
||||||
|
terminate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (terminate) {
|
if (terminate) {
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_count) {
|
if (read_count) {
|
||||||
|
|
Loading…
Reference in New Issue