P7 Logger to module
This commit is contained in:
parent
04948d0d4d
commit
08477f316e
@ -1,12 +1,12 @@
|
|||||||
module;
|
module;
|
||||||
|
|
||||||
#include "Logger.h"
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <ee_utils/utils.hpp>
|
#include <ee_utils/utils.hpp>
|
||||||
|
|
||||||
module Render;
|
module Render;
|
||||||
import std;
|
import std;
|
||||||
|
import utils;
|
||||||
|
|
||||||
ee_engine::IRenderer::IRenderer(GLFWwindow *window)
|
ee_engine::IRenderer::IRenderer(GLFWwindow *window)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
module;
|
module;
|
||||||
|
|
||||||
#include "Logger.h"
|
|
||||||
#include "compile_config.hpp"
|
#include "compile_config.hpp"
|
||||||
#include <ee_utils/utils.hpp>
|
#include <ee_utils/utils.hpp>
|
||||||
#include <xxhash.h>
|
#include <xxhash.h>
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
module;
|
module;
|
||||||
|
|
||||||
#include "Logger.h"
|
|
||||||
#include <ee_utils/utils.hpp>
|
#include <ee_utils/utils.hpp>
|
||||||
|
|
||||||
module Client;
|
module Client;
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
module;
|
module;
|
||||||
|
|
||||||
#include "Logger.h"
|
#include <ee_utils/platform.hpp>
|
||||||
|
|
||||||
|
|
||||||
module FileSystem;
|
module FileSystem;
|
||||||
import utils;
|
import utils;
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
module;
|
module;
|
||||||
|
|
||||||
#include "Logger.h"
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#define GLFW_GET_INPUT reinterpret_cast<GLFWInput*>(glfwGetWindowUserPointer(window))
|
#define GLFW_GET_INPUT reinterpret_cast<GLFWInput*>(glfwGetWindowUserPointer(window))
|
||||||
@ -8,6 +7,7 @@ module;
|
|||||||
|
|
||||||
module GLFWInput;
|
module GLFWInput;
|
||||||
import Engine;
|
import Engine;
|
||||||
|
import utils;
|
||||||
|
|
||||||
GLFWInput::GLFWInput(ee_engine::InputHandlers handlers) : ee_engine::IInput(handlers)
|
GLFWInput::GLFWInput(ee_engine::InputHandlers handlers) : ee_engine::IInput(handlers)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
#include "Logger.h"
|
|
||||||
#include "compile_config.hpp"
|
#include "compile_config.hpp"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
@ -10,15 +9,11 @@ import MagnumRender;
|
|||||||
import GLFWInput;
|
import GLFWInput;
|
||||||
import std;
|
import std;
|
||||||
|
|
||||||
|
|
||||||
IP7_Trace* Logger::trace;
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// Setup P7 logger
|
// Setup P7 logger
|
||||||
IP7_Client *p7client = P7_Create_Client(P7_SINK P7_LOGS_PATH);
|
Logger::Init(P7_SINK P7_LOGS_PATH);
|
||||||
P7_Set_Crash_Handler();
|
Logger::RegisterThread(L"Main");
|
||||||
Logger::trace = P7_Create_Trace(p7client, L"TC 1");
|
|
||||||
Logger::trace->Register_Thread(L"Main", 0);
|
|
||||||
|
|
||||||
LOG(INFO, "Etredia Empires, v%d.%d.%d", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);
|
LOG(INFO, "Etredia Empires, v%d.%d.%d", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);
|
||||||
|
|
||||||
@ -98,9 +93,8 @@ int main(int argc, char **argv)
|
|||||||
// Free memory
|
// Free memory
|
||||||
LOG(INFO, "Exit...");
|
LOG(INFO, "Exit...");
|
||||||
Engine::Shutdown();
|
Engine::Shutdown();
|
||||||
Logger::trace->Unregister_Thread(0);
|
Logger::UnregisterThread();
|
||||||
Logger::trace->Release();
|
Logger::Release();
|
||||||
p7client->Release();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "P7_Trace.h"
|
|
||||||
|
|
||||||
#define LOG(level, format, ...) Logger::trace->P7_DELIVER(0, EP7TRACE_LEVEL_##level, NULL, TM(format), __VA_ARGS__)
|
|
||||||
|
|
||||||
class Logger
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static IP7_Trace *trace;
|
|
||||||
};
|
|
||||||
@ -7,10 +7,10 @@ module;
|
|||||||
#include <Magnum/GL/Version.h>
|
#include <Magnum/GL/Version.h>
|
||||||
#include <Magnum/Math/Matrix4.h>
|
#include <Magnum/Math/Matrix4.h>
|
||||||
|
|
||||||
#include "Logger.h"
|
|
||||||
|
|
||||||
module MagnumRender;
|
module MagnumRender;
|
||||||
import :Materials;
|
import :Materials;
|
||||||
|
import utils;
|
||||||
|
|
||||||
ee_magnum::BaseMaterial::BaseMaterial(const std::string &vertSrc, const std::string &fragSrc)
|
ee_magnum::BaseMaterial::BaseMaterial(const std::string &vertSrc, const std::string &fragSrc)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,8 +2,6 @@ module;
|
|||||||
|
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
|
|
||||||
#include "Logger.h"
|
|
||||||
|
|
||||||
#include <Magnum/Platform/GLContext.h>
|
#include <Magnum/Platform/GLContext.h>
|
||||||
#include <Magnum/GL/Mesh.h>
|
#include <Magnum/GL/Mesh.h>
|
||||||
#include <Magnum/GL/Buffer.h>
|
#include <Magnum/GL/Buffer.h>
|
||||||
|
|||||||
@ -2,7 +2,11 @@
|
|||||||
#define ETREDIAEMPIRES_PLATFORM_HPP
|
#define ETREDIAEMPIRES_PLATFORM_HPP
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#define WIN_ERROR 0
|
||||||
|
#undef ERROR
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|||||||
@ -5,7 +5,10 @@ module;
|
|||||||
|
|
||||||
export module utils:lockfree;
|
export module utils:lockfree;
|
||||||
|
|
||||||
export using boost::lockfree::capacity;
|
export namespace boost
|
||||||
|
{
|
||||||
|
using lockfree::capacity;
|
||||||
|
|
||||||
export using boost::lockfree::queue;
|
using lockfree::queue;
|
||||||
export using boost::lockfree::spsc_queue;
|
using lockfree::spsc_queue;
|
||||||
|
}
|
||||||
148
utils/modules/logger.cppm
Normal file
148
utils/modules/logger.cppm
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
module;
|
||||||
|
|
||||||
|
#include <P7_Trace.h>
|
||||||
|
#undef ERROR
|
||||||
|
#undef TM
|
||||||
|
|
||||||
|
export module utils:logger;
|
||||||
|
import std;
|
||||||
|
|
||||||
|
namespace logger
|
||||||
|
{
|
||||||
|
template <std::size_t length>
|
||||||
|
struct wstring
|
||||||
|
{
|
||||||
|
wchar_t content[length];
|
||||||
|
constexpr operator const wchar_t*() const {return content;}
|
||||||
|
|
||||||
|
explicit constexpr wstring(const char (&str)[length]) : content{}
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < length; i++)
|
||||||
|
content[i] = static_cast<wchar_t>(str[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <std::size_t length>
|
||||||
|
constexpr wstring<length> TM(const char (&str)[length])
|
||||||
|
{
|
||||||
|
return wstring<length>(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LogLevel : std::uint8_t
|
||||||
|
{
|
||||||
|
TRACE,
|
||||||
|
DEBUG,
|
||||||
|
INFO,
|
||||||
|
WARNING,
|
||||||
|
ERROR,
|
||||||
|
CRITICAL,
|
||||||
|
};
|
||||||
|
|
||||||
|
class Logger;
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
struct LOG_WCHAR
|
||||||
|
{
|
||||||
|
LOG_WCHAR(
|
||||||
|
LogLevel level,
|
||||||
|
const wchar_t* format,
|
||||||
|
Args&&... args,
|
||||||
|
const std::source_location &location = std::source_location::current()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Logger::trace->Trace(
|
||||||
|
0,
|
||||||
|
static_cast<eP7Trace_Level>(level),
|
||||||
|
nullptr,
|
||||||
|
location.line(),
|
||||||
|
location.file_name(),
|
||||||
|
location.function_name(),
|
||||||
|
format,
|
||||||
|
std::forward<Args>(args)...
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Notice: logging char string supports only ASCII, use LOG_WCHAR with wchar string for UTF-8
|
||||||
|
template <std::size_t length, typename... Args>
|
||||||
|
struct LOG
|
||||||
|
{
|
||||||
|
LOG(
|
||||||
|
LogLevel level,
|
||||||
|
const char (&format)[length],
|
||||||
|
Args&&... args,
|
||||||
|
const std::source_location &location = std::source_location::current()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Logger::trace->Trace(
|
||||||
|
0,
|
||||||
|
static_cast<eP7Trace_Level>(level),
|
||||||
|
nullptr,
|
||||||
|
location.line(),
|
||||||
|
location.file_name(),
|
||||||
|
location.function_name(),
|
||||||
|
TM(format),
|
||||||
|
std::forward<Args>(args)...
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... Args> LOG_WCHAR(LogLevel, const wchar_t*, Args&&...) -> LOG_WCHAR<Args...>;
|
||||||
|
template <std::size_t length, typename... Args> LOG(LogLevel, const char (&)[length], Args&&...) -> LOG<length, Args...>;
|
||||||
|
|
||||||
|
class Logger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Logger() = delete;
|
||||||
|
|
||||||
|
static void Init(const wchar_t *options)
|
||||||
|
{
|
||||||
|
if (isReady)
|
||||||
|
{
|
||||||
|
LOG_WCHAR(WARNING, L"Logger already initialized.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
client = P7_Create_Client(options);
|
||||||
|
P7_Set_Crash_Handler();
|
||||||
|
trace = P7_Create_Trace(client, L"TC 1");
|
||||||
|
|
||||||
|
isReady = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Release()
|
||||||
|
{
|
||||||
|
trace->Release();
|
||||||
|
client->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RegisterThread(const wchar_t *name)
|
||||||
|
{
|
||||||
|
trace->Register_Thread(name, 0);
|
||||||
|
}
|
||||||
|
static void UnregisterThread()
|
||||||
|
{
|
||||||
|
trace->Unregister_Thread(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline static IP7_Client *client = nullptr;
|
||||||
|
inline static IP7_Trace *trace = nullptr;
|
||||||
|
|
||||||
|
inline static bool isReady = false;
|
||||||
|
|
||||||
|
template <typename... Args> friend struct LOG_WCHAR;
|
||||||
|
template <std::size_t length, typename... Args> friend struct LOG;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export using logger::Logger;
|
||||||
|
export using logger::LOG_WCHAR;
|
||||||
|
export using logger::LOG;
|
||||||
|
export using logger::LogLevel::TRACE;
|
||||||
|
export using logger::LogLevel::DEBUG;
|
||||||
|
export using logger::LogLevel::INFO;
|
||||||
|
export using logger::LogLevel::WARNING;
|
||||||
|
export using logger::LogLevel::ERROR;
|
||||||
|
export using logger::LogLevel::CRITICAL;
|
||||||
@ -3,5 +3,6 @@ export import :allocator;
|
|||||||
export import :worker;
|
export import :worker;
|
||||||
export import :buffers;
|
export import :buffers;
|
||||||
export import :lockfree;
|
export import :lockfree;
|
||||||
|
export import :logger;
|
||||||
|
|
||||||
export namespace ee_utils {}
|
export namespace ee_utils {}
|
||||||
@ -1,9 +1,6 @@
|
|||||||
module;
|
|
||||||
|
|
||||||
#include "Logger.h"
|
|
||||||
|
|
||||||
export module utils:worker;
|
export module utils:worker;
|
||||||
import :lockfree;
|
import :lockfree;
|
||||||
|
import :logger;
|
||||||
import std;
|
import std;
|
||||||
|
|
||||||
export namespace ee_utils
|
export namespace ee_utils
|
||||||
@ -48,6 +45,8 @@ export namespace ee_utils
|
|||||||
// TODO: maybe I should use lockfree::queue ?
|
// TODO: maybe I should use lockfree::queue ?
|
||||||
boost::lockfree::spsc_queue<TCommand, boost::lockfree::capacity<512>> commands;
|
boost::lockfree::spsc_queue<TCommand, boost::lockfree::capacity<512>> commands;
|
||||||
|
|
||||||
|
Worker() {};
|
||||||
|
|
||||||
void ProcessCommand(TCommand &command)
|
void ProcessCommand(TCommand &command)
|
||||||
{
|
{
|
||||||
if (command.type > maxCmdType || !commandsMapping[command.type])
|
if (command.type > maxCmdType || !commandsMapping[command.type])
|
||||||
@ -110,7 +109,7 @@ export namespace ee_utils
|
|||||||
|
|
||||||
void Threading()
|
void Threading()
|
||||||
{
|
{
|
||||||
Logger::trace->Register_Thread(threadName, 0);
|
Logger::RegisterThread(threadName);
|
||||||
LOG(INFO, "Thread started");
|
LOG(INFO, "Thread started");
|
||||||
|
|
||||||
Loop();
|
Loop();
|
||||||
@ -121,6 +120,7 @@ export namespace ee_utils
|
|||||||
void Loop()
|
void Loop()
|
||||||
{
|
{
|
||||||
TCommand commandBuffer{};
|
TCommand commandBuffer{};
|
||||||
|
// ReSharper disable once CppTooWideScope
|
||||||
std::vector<TCommand> incompleteCommands;
|
std::vector<TCommand> incompleteCommands;
|
||||||
while (!stoken->stop_requested())
|
while (!stoken->stop_requested())
|
||||||
{
|
{
|
||||||
@ -138,7 +138,7 @@ export namespace ee_utils
|
|||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
LOG(INFO, "Thread is released");
|
LOG(INFO, "Thread is released");
|
||||||
Logger::trace->Unregister_Thread(0);
|
Logger::UnregisterThread();
|
||||||
isRunning.store(false);
|
isRunning.store(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user