2018-08-03 09:19:12 +00:00
|
|
|
#include "debuglog.hpp"
|
2022-06-29 21:08:33 +00:00
|
|
|
|
2022-06-06 22:36:08 +00:00
|
|
|
#include <mutex>
|
2018-08-03 09:19:12 +00:00
|
|
|
|
2022-07-02 22:02:29 +00:00
|
|
|
#include <components/files/conversion.hpp>
|
2022-09-11 01:26:06 +00:00
|
|
|
#include <components/misc/strings/conversion.hpp>
|
2022-06-29 21:08:33 +00:00
|
|
|
|
2018-08-03 09:19:12 +00:00
|
|
|
namespace Debug
|
|
|
|
{
|
|
|
|
Level CurrentDebugLevel = Level::NoLevel;
|
|
|
|
}
|
|
|
|
|
2022-06-06 22:36:08 +00:00
|
|
|
static std::mutex sLock;
|
|
|
|
|
2022-06-29 21:08:33 +00:00
|
|
|
Log::Log(Debug::Level level)
|
2022-06-06 22:36:08 +00:00
|
|
|
: mShouldLog(level <= Debug::CurrentDebugLevel)
|
|
|
|
{
|
|
|
|
// 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 the app has no logging system enabled, log level is not specified.
|
|
|
|
// Show all messages without marker - we just use the plain cout in this case.
|
|
|
|
if (Debug::CurrentDebugLevel == Debug::NoLevel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::cout << static_cast<unsigned char>(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
Log::~Log()
|
|
|
|
{
|
|
|
|
if (!mShouldLog)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
sLock.unlock();
|
|
|
|
}
|
2022-06-29 21:08:33 +00:00
|
|
|
|
|
|
|
Log& Log::operator<<(const std::filesystem::path& rhs)
|
|
|
|
{
|
|
|
|
if (mShouldLog)
|
|
|
|
std::cout << Files::pathToUnicodeString(rhs);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2023-02-06 20:18:35 +00:00
|
|
|
Log& Log::operator<<(const std::u8string& rhs)
|
2023-02-06 11:12:24 +00:00
|
|
|
{
|
|
|
|
if (mShouldLog)
|
2023-02-06 20:18:35 +00:00
|
|
|
std::cout << Misc::StringUtils::u8StringToString(rhs);
|
2022-06-29 21:08:33 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-09-10 10:11:56 +00:00
|
|
|
Log& Log::operator<<(const std::u8string_view rhs)
|
2022-06-29 21:08:33 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|