mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-17 20:10:23 +03:00
* Use concrete log levels instead of prefixing the log string.
* Remove the "info" tag.
This commit is contained in:
@@ -5,30 +5,32 @@
|
||||
#include "LoggerWindows.hpp"
|
||||
#include "common/Util.hpp"
|
||||
|
||||
void LoggerWindows::print(const char* const str)
|
||||
void LoggerWindows::print(eLogLevel ll, const char* const str)
|
||||
{
|
||||
Logger::print(str);
|
||||
Logger::print(ll, str);
|
||||
|
||||
// wellp, this sucks, but it's fine
|
||||
OutputDebugStringA(GetTag(ll));
|
||||
OutputDebugStringA(str);
|
||||
OutputDebugStringA("\n");
|
||||
}
|
||||
|
||||
void LoggerWindows::print(std::string str)
|
||||
void LoggerWindows::print(eLogLevel ll, std::string str)
|
||||
{
|
||||
print(str.c_str());
|
||||
print(ll, str.c_str());
|
||||
}
|
||||
|
||||
void LoggerWindows::vprintf(const char* const fmt, va_list argPtr)
|
||||
void LoggerWindows::vprintf(eLogLevel ll, const char* const fmt, va_list argPtr)
|
||||
{
|
||||
print(Util::vformat(fmt, argPtr));
|
||||
print(ll, Util::vformat(fmt, argPtr));
|
||||
}
|
||||
|
||||
void LoggerWindows::printf(const char* const fmt, ...)
|
||||
void LoggerWindows::printf(eLogLevel ll, const char* const fmt, ...)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, fmt);
|
||||
|
||||
vprintf(fmt, argList);
|
||||
vprintf(ll, fmt, argList);
|
||||
|
||||
va_end(argList);
|
||||
}
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
class LoggerWindows : Logger
|
||||
{
|
||||
void print(const char* const str) override;
|
||||
void print(std::string str) override;
|
||||
void vprintf(const char* const fmt, va_list argPtr) override;
|
||||
void printf(const char* const fmt, ...) override;
|
||||
void print(eLogLevel, const char* const str) override;
|
||||
void print(eLogLevel, std::string str) override;
|
||||
void vprintf(eLogLevel, const char* const fmt, va_list argPtr) override;
|
||||
void printf(eLogLevel, const char* const fmt, ...) override;
|
||||
};
|
||||
@@ -24,29 +24,44 @@ Logger::~Logger()
|
||||
m_singleton = nullptr;
|
||||
}
|
||||
|
||||
void Logger::print(const char* const str)
|
||||
const char* Logger::GetTag(eLogLevel ll)
|
||||
{
|
||||
switch (ll)
|
||||
{
|
||||
default:
|
||||
return "Unk: ";
|
||||
case LOG_INFO:
|
||||
return "";
|
||||
case LOG_WARN:
|
||||
return "Warning: ";
|
||||
case LOG_ERR:
|
||||
return "ERROR: ";
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::print(eLogLevel ll, const char* const str)
|
||||
{
|
||||
// iProgramInCpp changed this to printf because he was worried that
|
||||
// the std::cout features wouldn't work in emscripten.
|
||||
::printf("%s\n", str);
|
||||
::printf("%s%s\n", GetTag(ll), str);
|
||||
}
|
||||
|
||||
void Logger::print(std::string str)
|
||||
void Logger::print(eLogLevel ll, std::string str)
|
||||
{
|
||||
print(str.c_str());
|
||||
print(ll, str.c_str());
|
||||
}
|
||||
|
||||
void Logger::vprintf(const char* const fmt, va_list argPtr)
|
||||
void Logger::vprintf(eLogLevel ll, const char* const fmt, va_list argPtr)
|
||||
{
|
||||
print(Util::vformat(fmt, argPtr));
|
||||
print(ll, Util::vformat(fmt, argPtr));
|
||||
}
|
||||
|
||||
void Logger::printf(const char* const fmt, ...)
|
||||
void Logger::printf(eLogLevel ll, const char* const fmt, ...)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, fmt);
|
||||
|
||||
vprintf(fmt, argList);
|
||||
vprintf(ll, fmt, argList);
|
||||
|
||||
va_end(argList);
|
||||
}
|
||||
@@ -2,6 +2,13 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
enum eLogLevel
|
||||
{
|
||||
LOG_INFO,
|
||||
LOG_WARN,
|
||||
LOG_ERR,
|
||||
};
|
||||
|
||||
class Logger
|
||||
{
|
||||
private:
|
||||
@@ -12,24 +19,27 @@ public:
|
||||
Logger();
|
||||
~Logger();
|
||||
|
||||
virtual void print(const char* const str);
|
||||
virtual void print(std::string str);
|
||||
virtual void vprintf(const char* const fmt, va_list argPtr);
|
||||
virtual void printf(const char* const fmt, ...);
|
||||
const char* GetTag(eLogLevel ll);
|
||||
virtual void print(eLogLevel, const char* const str);
|
||||
virtual void print(eLogLevel, std::string str);
|
||||
virtual void vprintf(eLogLevel, const char* const fmt, va_list argPtr);
|
||||
virtual void printf(eLogLevel, const char* const fmt, ...);
|
||||
};
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#define LOG(...) Logger::singleton()->printf(__VA_ARGS__)
|
||||
#define LOG(level, ...) Logger::singleton()->printf(level, __VA_ARGS__)
|
||||
|
||||
#ifdef PLATFORM_ANDROID
|
||||
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, "MinecraftPE", __VA_ARGS__)
|
||||
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, "MinecraftPE", __VA_ARGS__)
|
||||
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, "MinecraftPE", __VA_ARGS__)
|
||||
// TODO: Add a LoggerAndroid
|
||||
#define LOG(ignored, ...) __android_log_print(ANDROID_LOG_DEFAULT, "ReMinecraftPE", __VA_ARGS__)
|
||||
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, "ReMinecraftPE", __VA_ARGS__)
|
||||
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, "ReMinecraftPE", __VA_ARGS__)
|
||||
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, "ReMinecraftPE", __VA_ARGS__)
|
||||
#else
|
||||
#define LOG_I(...) LOG("[Info]: " __VA_ARGS__)
|
||||
#define LOG_W(...) LOG("[WARN]: " __VA_ARGS__)
|
||||
#define LOG_E(...) LOG("[ERROR]: " __VA_ARGS__)
|
||||
#define LOG_I(...) LOG(LOG_INFO, __VA_ARGS__)
|
||||
#define LOG_W(...) LOG(LOG_WARN, __VA_ARGS__)
|
||||
#define LOG_E(...) LOG(LOG_ERR, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user