According to my own documentation, the project tree should look entirely different. Also, it should use CMake instead of Make. This commit introduces changes that will make my project tree to adhere to my own documentation.
76 lines
1.4 KiB
C++
76 lines
1.4 KiB
C++
/**
|
|
* @file log.hpp
|
|
* @author Piotr Krygier (everyonencancode@gmail.com)
|
|
* @brief Logging interfaces
|
|
* @version 0.1
|
|
* @date 2022-02-11
|
|
*
|
|
* @copyright Copyright (c) 2022
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <sstream>
|
|
|
|
#ifndef LOG_LEVEL
|
|
#define LOG_LEVEL LOGLEVEL_DEBUG
|
|
#endif
|
|
|
|
#define LOGT rse::log::Logger(rse::log::LOGLEVEL_TRACE)
|
|
#define LOGD rse::log::Logger(rse::log::LOGLEVEL_DEBUG)
|
|
#define LOGI rse::log::Logger(rse::log::LOGLEVEL_INFO)
|
|
#define LOGW rse::log::Logger(rse::log::LOGLEVEL_WARNING)
|
|
#define LOGE rse::log::Logger(rse::log::LOGLEVEL_ERROR)
|
|
#define LOGF rse::log::Logger(rse::log::LOGLEVEL_FATAL)
|
|
|
|
|
|
|
|
namespace rse::log
|
|
{
|
|
|
|
/**
|
|
* @brief Log level. Is not an enum class, because level is being compared to enable prints
|
|
*
|
|
*/
|
|
typedef enum
|
|
{
|
|
LOGLEVEL_TRACE = 1,
|
|
LOGLEVEL_DEBUG = 2,
|
|
LOGLEVEL_INFO = 3,
|
|
LOGLEVEL_WARNING = 4,
|
|
LOGLEVEL_ERROR = 5,
|
|
LOGLEVEL_FATAL = 6
|
|
} LogLevel;
|
|
|
|
/**
|
|
* @brief Class used indirectly as a logger.
|
|
*
|
|
*/
|
|
class Logger {
|
|
private:
|
|
bool printMessage;
|
|
std::stringstream mMessageBuffer;
|
|
|
|
public:
|
|
/**
|
|
* @brief Construct a new Logger object
|
|
*
|
|
*/
|
|
Logger(LogLevel);
|
|
~Logger();
|
|
|
|
/**
|
|
* @brief For log printing. I want it to work like log << "Message " << args;
|
|
*
|
|
*/
|
|
template <typename T>
|
|
Logger& operator<<(T&& message)
|
|
{
|
|
if (printMessage)
|
|
mMessageBuffer << message;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
} // namespace rse::log
|