initial work on loggin class

This commit is contained in:
georgemoralis 2023-05-16 19:31:53 +03:00
parent 08f8da2fea
commit 81ca77a464
4 changed files with 56 additions and 2 deletions

View File

@ -26,7 +26,7 @@ add_executable(shadps4
src/Loader/Elf.cpp src/Loader/Elf.cpp
src/Loader/Elf.h src/Loader/Elf.h
src/GUI/ElfViewer.cpp src/GUI/ElfViewer.cpp
src/GUI/ElfViewer.h) src/GUI/ElfViewer.h "src/Util/Log.h" "src/Util/Log.cpp")
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)

17
src/Util/Log.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <vector>
#include <spdlog/common.h>
#include <spdlog/sinks/stdout_color_sinks.h>
namespace logging {
std::vector<spdlog::sink_ptr> sinks;
int init(bool use_stdout) {
sinks.clear();//clear existing sinks
if (use_stdout)//if we use stdout window then init it as well
sinks.push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
return 0;//all ok
}
}

35
src/Util/Log.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#include <spdlog/spdlog.h>
namespace logging {
#define LOG_TRACE SPDLOG_TRACE
#define LOG_DEBUG SPDLOG_DEBUG
#define LOG_INFO SPDLOG_INFO
#define LOG_WARN SPDLOG_WARN
#define LOG_ERROR SPDLOG_ERROR
#define LOG_CRITICAL SPDLOG_CRITICAL
#define LOG_TRACE_IF(flag, ...) \
if (flag) \
LOG_TRACE(__VA_ARGS__)
#define LOG_DEBUG_IF(flag, ...) \
if (flag) \
LOG_DEBUG(__VA_ARGS__)
#define LOG_INFO_IF(flag, ...) \
if (flag) \
LOG_INFO(__VA_ARGS__)
#define LOG_WARN_IF(flag, ...) \
if (flag) \
LOG_WARN(__VA_ARGS__)
#define LOG_ERROR_IF(flag, ...) \
if (flag) \
LOG_ERROR(__VA_ARGS__)
#define LOG_CRITICAL_IF(flag, ...) \
if (flag) \
LOG_CRITICAL(__VA_ARGS__)
int init(bool use_stdout);
}

View File

@ -18,6 +18,7 @@
#include "types.h" #include "types.h"
#include "Loader/Elf.h" #include "Loader/Elf.h"
#include "GUI/ElfViewer.h" #include "GUI/ElfViewer.h"
#include "Util/Log.h"
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details. // This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
@ -27,7 +28,8 @@
// Main code // Main code
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
const char* const path = argv[1]; //argument 1 is the path of self file to boot logging::init(true);//init logging
const char* const path = argv[1]; //argument 1 is the path of self file to boot
Elf* elf = new Elf; Elf* elf = new Elf;
elf->Open(path); elf->Open(path);