Add log formatting support
This commit is contained in:
@@ -17,8 +17,8 @@
|
|||||||
#define ABORT_SIGNAL SIGABRT
|
#define ABORT_SIGNAL SIGABRT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NF_ASSERT(x, y) if(!(x)) { NF_DANGER(y); raise(ABORT_SIGNAL); }
|
#define NF_ASSERT(x, y) if(!(x)) { NF_DANGER("Assert: {%s}, %s", #x, y); raise(ABORT_SIGNAL); }
|
||||||
#define NF_CORE_ASSERT(x, y) if(!(x)) { NF_CORE_DANGER(y); raise(ABORT_SIGNAL); }
|
#define NF_CORE_ASSERT(x, y) if(!(x)) { NF_CORE_DANGER("Assert: {%s}, %s", #x, y); raise(ABORT_SIGNAL); }
|
||||||
#else
|
#else
|
||||||
#define NF_ASSERT(x, y)
|
#define NF_ASSERT(x, y)
|
||||||
#define NF_CORE_ASSERT(x, y)
|
#define NF_CORE_ASSERT(x, y)
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#include <cstdio> // printf
|
|
||||||
|
|
||||||
#include "inferno/log.h"
|
#include "inferno/log.h"
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
@@ -25,29 +23,4 @@ namespace Inferno {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::log(const char* message, const char* level)
|
|
||||||
{
|
|
||||||
printf("%s%s: %s\033[0m\n", level, m_name, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::info(const char* message)
|
|
||||||
{
|
|
||||||
this->log(message, "\x1B[34m");
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::warn(const char* message)
|
|
||||||
{
|
|
||||||
this->log(message, "\x1B[33m");
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::danger(const char* message)
|
|
||||||
{
|
|
||||||
this->log(message, "\x1B[31m");
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::success(const char* message)
|
|
||||||
{
|
|
||||||
this->log(message, "\x1B[32m");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-16
@@ -1,7 +1,9 @@
|
|||||||
#ifndef LOG_H
|
#ifndef LOG_H
|
||||||
#define LOG_H
|
#define LOG_H
|
||||||
|
|
||||||
#include <memory>
|
#include <cstdio> // sprintf, printf
|
||||||
|
#include <cstring> // strlen
|
||||||
|
#include <memory> // shared_ptr
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
@@ -28,11 +30,43 @@ namespace Inferno {
|
|||||||
Logger(const char* name);
|
Logger(const char* name);
|
||||||
~Logger();
|
~Logger();
|
||||||
|
|
||||||
void log(const char* message, const char* level = "");
|
template<typename ...A>
|
||||||
void info(const char* message);
|
void print(const char* color, const char* format, A... arguments)
|
||||||
void warn(const char* message);
|
{
|
||||||
void danger(const char* message);
|
char buffer[10 + strlen(color) + strlen(m_name) + strlen(format)];
|
||||||
void success(const char* message);
|
sprintf(buffer, "%s%s: %s\033[0m\n", color, m_name, format);
|
||||||
|
printf(buffer, arguments...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
void log(const char* format, A... arguments)
|
||||||
|
{
|
||||||
|
this->print("", format, arguments...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
void info(const char* format, A... arguments)
|
||||||
|
{
|
||||||
|
this->print("\x1B[34m", format, arguments...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
void warn(const char* format, A... arguments)
|
||||||
|
{
|
||||||
|
this->print("\x1B[33m", format, arguments...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
void danger(const char* format, A... arguments)
|
||||||
|
{
|
||||||
|
this->print("\x1B[31m", format, arguments...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
void success(const char* format, A... arguments)
|
||||||
|
{
|
||||||
|
this->print("\x1B[32m", format, arguments...);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* m_name;
|
const char* m_name;
|
||||||
@@ -40,16 +74,16 @@ namespace Inferno {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NF_CORE_LOG(x) Inferno::Log::getCoreLogger()->log(x)
|
#define NF_CORE_LOG(...) Inferno::Log::getCoreLogger()->log(__VA_ARGS__)
|
||||||
#define NF_CORE_INFO(x) Inferno::Log::getCoreLogger()->info(x)
|
#define NF_CORE_INFO(...) Inferno::Log::getCoreLogger()->info(__VA_ARGS__)
|
||||||
#define NF_CORE_WARN(x) Inferno::Log::getCoreLogger()->warn(x)
|
#define NF_CORE_WARN(...) Inferno::Log::getCoreLogger()->warn(__VA_ARGS__)
|
||||||
#define NF_CORE_DANGER(x) Inferno::Log::getCoreLogger()->danger(x)
|
#define NF_CORE_DANGER(...) Inferno::Log::getCoreLogger()->danger(__VA_ARGS__)
|
||||||
#define NF_CORE_SUCCESS(x) Inferno::Log::getCoreLogger()->success(x)
|
#define NF_CORE_SUCCESS(...) Inferno::Log::getCoreLogger()->success(__VA_ARGS__)
|
||||||
|
|
||||||
#define NF_LOG(x) Inferno::Log::getGameLogger()->log(x)
|
#define NF_LOG(...) Inferno::Log::getGameLogger()->log(__VA_ARGS__)
|
||||||
#define NF_INFO(x) Inferno::Log::getGameLogger()->info(x)
|
#define NF_INFO(...) Inferno::Log::getGameLogger()->info(__VA_ARGS__)
|
||||||
#define NF_WARN(x) Inferno::Log::getGameLogger()->warn(x)
|
#define NF_WARN(...) Inferno::Log::getGameLogger()->warn(__VA_ARGS__)
|
||||||
#define NF_DANGER(x) Inferno::Log::getGameLogger()->danger(x)
|
#define NF_DANGER(...) Inferno::Log::getGameLogger()->danger(__VA_ARGS__)
|
||||||
#define NF_SUCCESS(x) Inferno::Log::getGameLogger()->success(x)
|
#define NF_SUCCESS(...) Inferno::Log::getGameLogger()->success(__VA_ARGS__)
|
||||||
|
|
||||||
#endif // LOG_H
|
#endif // LOG_H
|
||||||
|
|||||||
Reference in New Issue
Block a user