Skip to content

File Logger.hpp

File List > Engine > include > Logging > Logger.hpp

Go to the documentation of this file

#ifndef ENGINE_LOGGING_LOGGER_HPP_
#define ENGINE_LOGGING_LOGGER_HPP_

#include "Logging/LogBuffer.hpp"
#include "Logging/LogConfig.hpp"
#include "Logging/LogWriter.hpp"
#include <string>
#include <utility>

namespace Engine {

inline void emit(LogLevel level, LogAudience audience, std::string msg) {
    if (audience == LogAudience::User) {
        GetLogBuffer().Push(level, msg);
    }
    EnqueueLog(level, std::move(msg));
}

inline void log_error(std::string msg) {
    emit(LogLevel::Error, LogAudience::Engine, std::move(msg));
}

inline void log_user_error(std::string msg) {
    emit(LogLevel::Error, LogAudience::User, std::move(msg));
}

inline void log_debug(std::string msg) {
    emit(LogLevel::Debug, LogAudience::Engine, std::move(msg));
}

inline void log_info(std::string msg) {
    emit(LogLevel::Info, LogAudience::Engine, std::move(msg));
}

} // namespace Engine

#if ENGINE_LOG_LEVEL >= ENGINE_LOG_ERROR
#define log_error(msg) Engine::log_error((msg))
#define log_user_error(msg) Engine::log_user_error((msg))
#else
#define log_error(msg) ((void)0)
#define log_user_error(msg) ((void)0)
#endif

#if ENGINE_LOG_LEVEL >= ENGINE_LOG_DEBUG
#define log_debug(msg) Engine::log_debug((msg))
#else
#define log_debug(msg) ((void)0)
#endif

#if ENGINE_LOG_LEVEL >= ENGINE_LOG_INFO
#define log_info(msg) Engine::log_info((msg))
#else
#define log_info(msg) ((void)0)
#endif

#endif // ENGINE_LOGGING_LOGGER_HPP_