Fixing Logging. DevPlayground compiles and runs on Linux now.

This commit is contained in:
Thorben Höhne
2025-02-18 00:50:10 +01:00
parent defa41b42a
commit d6362a62df
8 changed files with 179 additions and 39 deletions

View File

@@ -22,5 +22,8 @@ ${StartingPointPCH}
add_compile_definitions(P_LINUX_BUILD)
add_compile_definitions(P_DEBUG)
# fmt for spdlog. It uses the external module which needs to be linked manually
find_package(fmt)
target_link_libraries(PhanesCore fmt::fmt)
target_include_directories(PhanesCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)

View File

@@ -6,13 +6,19 @@
namespace Phanes::Core::Logging
{
static Phanes::Ref<spdlog::logger> _PEngineLogger;
static Phanes::Ref<spdlog::logger> _PAppLogger;
class Logger {
void Init();
public:
inline std::shared_ptr<spdlog::logger>& PEngineLogger() { return _PEngineLogger; };
inline std::shared_ptr<spdlog::logger>& PAppLogger() { return _PAppLogger; };
static void Init();
static std::shared_ptr<spdlog::logger>& PEngineLogger() { return _PEngineLogger; }
static std::shared_ptr<spdlog::logger>& PAppLogger() { return _PAppLogger; }
private:
static std::shared_ptr<spdlog::logger> _PEngineLogger;
static std::shared_ptr<spdlog::logger> _PAppLogger;
};
}
@@ -22,18 +28,18 @@ namespace PLog = Phanes::Core::Logging; // User Macros
// Default logger
#define PENGINE_LOG_TRACE(...) ::Phanes::Core::Logging::PEngineLogger()->trace(__VA_ARGS__)
#define PENGINE_LOG_INFO(...) ::Phanes::Core::Logging::PEngineLogger()->info(__VA_ARGS__)
#define PENGINE_LOG_WARN(...) ::Phanes::Core::Logging::PEngineLogger()->warn(__VA_ARGS__)
#define PENGINE_LOG_ERROR(...) ::Phanes::Core::Logging::PEngineLogger()->error(__VA_ARGS__)
#define PENGINE_LOG_FATAL(...) ::Phanes::Core::Logging::PEngineLogger()->critical(__VA_ARGS__)
#define PENGINE_LOG_TRACE(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->trace(__VA_ARGS__)
#define PENGINE_LOG_INFO(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->info(__VA_ARGS__)
#define PENGINE_LOG_WARN(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->warn(__VA_ARGS__)
#define PENGINE_LOG_ERROR(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->error(__VA_ARGS__)
#define PENGINE_LOG_FATAL(...) ::Phanes::Core::Logging::Logger::PEngineLogger()->critical(__VA_ARGS__)
#define PAPP_LOG_TRACE(...) ::Phanes::Core::Logging::PAppLogger()->trace(__VA_ARGS__)
#define PAPP_LOG_INFO(...) ::Phanes::Core::Logging::PAppLogger()->info(__VA_ARGS__)
#define PAPP_LOG_WARN(...) ::Phanes::Core::Logging::PAppLogger()->warn(__VA_ARGS__)
#define PAPP_LOG_ERROR(...) ::Phanes::Core::Logging::PAppLogger()->error(__VA_ARGS__)
#define PAPP_LOG_FATAL(...) ::Phanes::Core::Logging::PAppLogger()->critical(__VA_ARGS__)
#define PAPP_LOG_TRACE(...) ::Phanes::Core::Logging::Logger::PAppLogger()->trace(__VA_ARGS__)
#define PAPP_LOG_INFO(...) ::Phanes::Core::Logging::Logger::PAppLogger()->info(__VA_ARGS__)
#define PAPP_LOG_WARN(...) ::Phanes::Core::Logging::Logger::PAppLogger()->warn(__VA_ARGS__)
#define PAPP_LOG_ERROR(...) ::Phanes::Core::Logging::Logger::PAppLogger()->error(__VA_ARGS__)
#define PAPP_LOG_FATAL(...) ::Phanes::Core::Logging::Logger::PAppLogger()->critical(__VA_ARGS__)
#else

View File

@@ -1,6 +1,13 @@
#include "Core/Logging/Logging.h"
void Phanes::Core::Logging::Init()
namespace Phanes::Core::Logging
{
std::shared_ptr<spdlog::logger> Logger::_PEngineLogger;
std::shared_ptr<spdlog::logger> Logger::_PAppLogger;
} // namespace Phanes::Core::Logging
void Phanes::Core::Logging::Logger::Init()
{
spdlog::set_pattern("%^[%n][%T][%l]:%$ %v");

View File

@@ -7,14 +7,11 @@ extern Phanes::Core::Application::PhanesProject* Phanes::Core::Application::Crea
int main(int argc, char** argv)
{
Phanes::Core::Logging::Init();
Phanes::Core::Logging::Logger::Init();
PENGINE_LOG_INFO("Logger initialized!");
PENGINE_LOG_INFO("Welcome to PhanesEngine!");
auto phanes_game = Phanes::Core::Application::CreatePhanesGame();
PENGINE_LOG_INFO("Loading project {0}...", phanes_game->GetName());
phanes_game->Run();

View File

@@ -1,24 +1,25 @@
#include "Core/StartingPoint/StartingPoint.h"
#include "Core/Logging/Logging.h"
static void IdleMsg()
{
std::cout << "\n\nWelcome to PhanesEngine!" << std::endl << std::endl;
std::cout << "\nWelcome to PhanesEngine!\n";
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "It's silent..." << std::endl << std::endl;
std::cout << "It's silent...\n";
std::this_thread::sleep_for(std::chrono::seconds(3));
std::cout << "To silent." << std::endl;
std::cout << "To silent.\n";
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "\nI will go now" << std::endl;
std::cout << "I will go now\n";
std::this_thread::sleep_for(std::chrono::seconds(4));
std::cout << "\nGood by!" << std::endl;
std::cout << "Good by!\n\n";
std::this_thread::sleep_for(std::chrono::seconds(3));
}
@@ -27,11 +28,13 @@ static void IdleMsg()
Phanes::Core::Application::PhanesProject::PhanesProject(std::string _ProjectName)
: projectName(_ProjectName)
{};
{
PAPP_LOG_INFO("Loading project: {0}", this->GetName());
};
Phanes::Core::Application::PhanesProject::~PhanesProject()
{
this->projectName = "Unnamed Project";
PAPP_LOG_INFO("Unloading project: {0}", this->GetName());
};
std::string Phanes::Core::Application::PhanesProject::GetName()