Skip to content

Commit

Permalink
Ensure file logging end message is written
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler authored and CZDanol committed Feb 21, 2025
1 parent 310b7f8 commit 3998fc2
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/logging/log_dest_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ namespace file {
unique_file_ptr file;

BufferChunk wip_chunk;

void write_buffer() {
while (!buffer.isEmpty()) {
BufferChunk chunk = buffer.dequeue();
fwrite(chunk.data.data(), 1, chunk.size, file.get());
}
}

~Data() {
if (file) {
write_buffer();
}
}
};

std::atomic_bool is_enabled = false;
Expand All @@ -50,10 +63,7 @@ static void file_log_write(AsyncJobExecutionControl &) {

const bool was_overflow = data->buffer.isFull();

while (!data->buffer.isEmpty()) {
BufferChunk chunk = data->buffer.dequeue();
fwrite(chunk.data.data(), 1, chunk.size, data->file.get());
}
data->write_buffer();

// If we fail writing, disable the logger
if (ferror(data->file.get())) {
Expand Down

0 comments on commit 3998fc2

Please sign in to comment.