1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#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;
}
|