mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2026-10-18 21:42:36 +00:00
Make abseil logging sink thread-safe
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include <fstream> // for ofstream
|
||||
#include <iostream> // for operator<<
|
||||
#include <memory> // for unique_ptr
|
||||
#include <mutex> // for lock_guard, mutex
|
||||
#include <ostream> // for std::flush
|
||||
#include <string> // for string
|
||||
|
||||
@@ -81,10 +82,12 @@ public:
|
||||
}
|
||||
void Send(const absl::LogEntry& entry) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logfile_mutex);
|
||||
logfile << entry.text_message_with_prefix_and_newline() << std::flush;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex logfile_mutex;
|
||||
std::ofstream logfile;
|
||||
std::string filename;
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
@@ -61,10 +62,12 @@ public:
|
||||
}
|
||||
void Send(const absl::LogEntry& entry) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logfile_mutex);
|
||||
logfile << entry.text_message_with_prefix_and_newline() << std::flush;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex logfile_mutex;
|
||||
std::ofstream logfile;
|
||||
};
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <numeric>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
@@ -89,10 +90,12 @@ public:
|
||||
}
|
||||
void Send(const absl::LogEntry& entry) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logfile_mutex);
|
||||
logfile << entry.text_message_with_prefix_and_newline() << std::flush;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex logfile_mutex;
|
||||
std::ofstream logfile;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
@@ -63,10 +64,12 @@ public:
|
||||
}
|
||||
void Send(const absl::LogEntry& entry) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logfile_mutex);
|
||||
logfile << entry.text_message_with_prefix_and_newline() << std::flush;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex logfile_mutex;
|
||||
std::ofstream logfile;
|
||||
std::string filename;
|
||||
};
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stdexcept> // for logic_error
|
||||
#include <string>
|
||||
#include <thread>
|
||||
@@ -122,10 +123,12 @@ public:
|
||||
}
|
||||
void Send(const absl::LogEntry& entry) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logfile_mutex);
|
||||
logfile << entry.text_message_with_prefix_and_newline() << std::flush;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex logfile_mutex;
|
||||
std::ofstream logfile;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user