Files
XCEngine/engine/include/XCEngine/Debug/Logger.h

82 lines
2.5 KiB
C++

#pragma once
#include "LogLevel.h"
#include "LogCategory.h"
#include "ILogSink.h"
#include <XCEngine/Core/Containers/String.h>
#include "../Threading/Mutex.h"
#include <memory>
#include <source_location>
#include <vector>
namespace XCEngine {
namespace Debug {
class Logger {
public:
static Logger& Get();
void Initialize();
void Shutdown();
void AddSink(std::unique_ptr<ILogSink> sink);
void RemoveSink(ILogSink* sink);
void Log(LogLevel level, LogCategory category,
const Containers::String& message,
const std::source_location& location = std::source_location::current());
void Log(LogLevel level, LogCategory category,
const Containers::String& message, const char* file,
int32_t line = 0, const char* function = nullptr);
void Verbose(
LogCategory category,
const Containers::String& message,
const std::source_location& location = std::source_location::current());
void Debug(
LogCategory category,
const Containers::String& message,
const std::source_location& location = std::source_location::current());
void Info(
LogCategory category,
const Containers::String& message,
const std::source_location& location = std::source_location::current());
void Warning(
LogCategory category,
const Containers::String& message,
const std::source_location& location = std::source_location::current());
void Error(
LogCategory category,
const Containers::String& message,
const std::source_location& location = std::source_location::current());
void Fatal(
LogCategory category,
const Containers::String& message,
const std::source_location& location = std::source_location::current());
void SetMinimumLevel(LogLevel level);
void SetCategoryEnabled(LogCategory category, bool enabled);
private:
Logger() = default;
~Logger() = default;
std::vector<std::unique_ptr<ILogSink>> m_sinks;
LogLevel m_minimumLevel = LogLevel::Verbose;
bool m_categoryEnabled[11] = { true, true, true, true, true, true, true, true, true, true, true };
Threading::Mutex m_mutex;
bool m_initialized = false;
};
#define XE_LOG(category, level, message) \
XCEngine::Debug::Logger::Get().Log(level, category, message)
#define XE_ASSERT(condition, message) \
if (!(condition)) { \
XCEngine::Debug::Logger::Get().Fatal(XCEngine::Debug::LogCategory::General, message); \
}
} // namespace Debug
} // namespace XCEngine