31 auto flags = std::ofstream::binary;
33 flags |= std::ofstream::app;
35 file_.open(path, flags);
37 throw std::runtime_error(
"Cannot open " + path +
" for writing");
39 thread_ = std::thread([
this]() {
41 pthread_setname_np(
"logger_thread");
43 pthread_setname_np(pthread_self(),
"logger_thread");
50 std::this_thread::sleep_for(std::chrono::microseconds(100));
58 if (thread_.joinable()) {
66 char *ndata =
new char[size];
67 std::memcpy(ndata, data, size);
68 return circular_buffer_.
push({ndata, size});
71 void Logger::flush_buffer() {
72 while (circular_buffer_.
pop(pop_)) {
73 char *data = pop_.first;
74 size_t size = pop_.second;
75 file_.write(data,
static_cast<int>(size));