Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
1.3 kB · 68 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869#include "debuglog.hpp"
#include <mutex>
#include <components/files/conversion.hpp>#include <components/misc/strings/conversion.hpp>
static std::mutex sLock;
Debug::Level Log::sMinDebugLevel = Debug::All;bool Log::sWriteLevel = false;
Log::Log(Debug::Level level) : mShouldLog(level <= sMinDebugLevel){ // No need to hold the lock if there will be no logging anyway if (!mShouldLog) return;
// Locks a global lock while the object is alive sLock.lock();
if (!sWriteLevel) return;
std::cout << static_cast<unsigned char>(level);}
Log::~Log(){ if (!mShouldLog) return;
std::cout << std::endl; sLock.unlock();}
Log& Log::operator<<(const std::filesystem::path& rhs){ if (mShouldLog) std::cout << Files::pathToUnicodeString(rhs);
return *this;}
Log& Log::operator<<(const std::u8string& rhs){ if (mShouldLog) std::cout << Misc::StringUtils::u8StringToString(rhs);
return *this;}
Log& Log::operator<<(const std::u8string_view rhs){ if (mShouldLog) std::cout << Misc::StringUtils::u8StringToString(rhs);
return *this;}
Log& Log::operator<<(const char8_t* rhs){ if (mShouldLog) std::cout << Misc::StringUtils::u8StringToString(rhs);
return *this;}