TMP / Fixed logging.cpp

This commit is contained in:
OLEGSHA 2023-03-28 21:39:40 +02:00
parent 08b5661934
commit 2fb324672a
2 changed files with 7 additions and 3 deletions

View File

@ -20,7 +20,7 @@ class LogSinkBackend {
void flush();
public:
LogSinkBackend() {}
LogSinkBackend() = default;
std::ostream &getOutput() { return buffer; }
@ -51,8 +51,11 @@ std::ofstream openLogFile() {
}
} // namespace
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables): TODO
std::mutex logFileMutex;
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::ofstream logFile = openLogFile();
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
thread_local detail::LogSinkBackend theBackend;
std::ostream &detail::LogSink::getStream() const {
@ -77,7 +80,7 @@ detail::LogSink::~LogSink() {
}
}
detail::LogSink::LogSink(LogSink &&moveFrom)
detail::LogSink::LogSink(LogSink &&moveFrom) noexcept
: isCurrentSink(moveFrom.isCurrentSink) {
moveFrom.isCurrentSink = false;
}
@ -98,6 +101,7 @@ void detail::LogSinkBackend::flush() {
namespace {
// FIXME This approach is horribly inefficient. It is also unsafe if any
// other piece of code wants access to std::localtime.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::mutex getLocalTimeMutex;
std::tm getLocalTimeAndDontExplodePlease() {
std::lock_guard<std::mutex> lock(getLocalTimeMutex);

View File

@ -23,7 +23,7 @@ class LogSink : private progressia::main::NonCopyable {
LogSink(bool isCurrentSink);
~LogSink();
LogSink(LogSink &&);
LogSink(LogSink &&) noexcept;
template <typename T>
friend const LogSink &operator<<(const LogSink &sink, const T &x) {