From 83089af95be8771f85ef56e822605366337cc565 Mon Sep 17 00:00:00 2001 From: lvntky Date: Thu, 20 Jun 2024 14:02:07 +0300 Subject: [PATCH] [refactor] arrange log level --- cmake/SourcesAndHeaders.cmake | 2 +- include/cvm/log.hpp | 16 +++++++--------- src/classfile/classfile.cpp | 8 ++++---- src/log.cpp | 22 ---------------------- 4 files changed, 12 insertions(+), 36 deletions(-) delete mode 100644 src/log.cpp diff --git a/cmake/SourcesAndHeaders.cmake b/cmake/SourcesAndHeaders.cmake index 053b758..324b324 100644 --- a/cmake/SourcesAndHeaders.cmake +++ b/cmake/SourcesAndHeaders.cmake @@ -1,6 +1,6 @@ set(sources src/classfile/classfile.cpp - src/log.cpp + ) set(exe_sources diff --git a/include/cvm/log.hpp b/include/cvm/log.hpp index dba74c3..6286f68 100644 --- a/include/cvm/log.hpp +++ b/include/cvm/log.hpp @@ -6,14 +6,12 @@ #define LOG_OK "OK" #define LOG_NOK "NOK" -#define DEBUG_ENABLED 1 -class Log{ -public: - static Log& getInstance(); - std::shared_ptr getLogger(); -private: - Log(); // Private constructor (singleton pattern) - std::shared_ptr logger; // The actual logger instance -}; +#define DEBUG_ENABLED 0 +void setLevel() { + if(DEBUG_ENABLED) { + spdlog::set_level(spdlog::level::debug); + + } +} #endif //__LOG_HPP__ diff --git a/src/classfile/classfile.cpp b/src/classfile/classfile.cpp index b612462..76e9ae7 100644 --- a/src/classfile/classfile.cpp +++ b/src/classfile/classfile.cpp @@ -6,7 +6,7 @@ uint16_t Classfile::readShort(const uint8_t* bytes, size_t& offset) { - spdlog::set_level(spdlog::level::debug); + setLevel(); spdlog::debug("Reading short at offset: {}", offset); uint16_t value = (bytes[offset] << 8 | bytes[offset + 1]); offset += 2; @@ -16,7 +16,7 @@ uint16_t Classfile::readShort(const uint8_t* bytes, size_t& offset) uint32_t Classfile::readInt(const uint8_t* bytes, size_t& offset) { - spdlog::set_level(spdlog::level::debug); + setLevel(); spdlog::debug("Reading int at offset: {}", offset); uint32_t value = (bytes[offset] << 24) | (bytes[offset + 1] << 16) | (bytes[offset + 2] << 8) | bytes[offset + 3]; offset += 4; @@ -26,7 +26,7 @@ uint32_t Classfile::readInt(const uint8_t* bytes, size_t& offset) uint64_t Classfile::readLong(const uint8_t* bytes, size_t& offset) { - spdlog::set_level(spdlog::level::debug); + setLevel(); spdlog::debug("Reading long at offset: {}", offset); uint64_t value = (static_cast(bytes[offset]) << 56) | (static_cast(bytes[offset + 1]) << 48) | (static_cast(bytes[offset + 2]) << 40) | (static_cast(bytes[offset + 3]) << 32) | @@ -39,7 +39,7 @@ uint64_t Classfile::readLong(const uint8_t* bytes, size_t& offset) double Classfile::readDouble(const uint8_t* bytes, size_t& offset) { - spdlog::set_level(spdlog::level::debug); + setLevel(); spdlog::debug("Reading double at offset: {}", offset); uint64_t longValue = readLong(bytes, offset); double value; diff --git a/src/log.cpp b/src/log.cpp deleted file mode 100644 index 03a9051..0000000 --- a/src/log.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "../include/cvm/log.hpp" - -Log::Log() -{ - // Initialize the logger (stdout logger in this case) - // spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v"); - if (DEBUG_ENABLED) - { - spdlog::set_level(spdlog::level::debug); // Set global log level to debug - } -} - -Log& Log::getInstance() -{ - static Log instance; // Guaranteed to be destroyed and instantiated on first use - return instance; -} - -std::shared_ptr Log::getLogger() -{ - return logger; -}