Skip to content

Commit

Permalink
[refactor] arrange log level
Browse files Browse the repository at this point in the history
  • Loading branch information
lvntky committed Jun 20, 2024
1 parent c1c854c commit 83089af
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cmake/SourcesAndHeaders.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(sources
src/classfile/classfile.cpp
src/log.cpp

)

set(exe_sources
Expand Down
16 changes: 7 additions & 9 deletions include/cvm/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<spdlog::logger> getLogger();
private:
Log(); // Private constructor (singleton pattern)
std::shared_ptr<spdlog::logger> logger; // The actual logger instance
};
#define DEBUG_ENABLED 0

void setLevel() {
if(DEBUG_ENABLED) {
spdlog::set_level(spdlog::level::debug);

}
}
#endif //__LOG_HPP__
8 changes: 4 additions & 4 deletions src/classfile/classfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<uint64_t>(bytes[offset]) << 56) | (static_cast<uint64_t>(bytes[offset + 1]) << 48) |
(static_cast<uint64_t>(bytes[offset + 2]) << 40) | (static_cast<uint64_t>(bytes[offset + 3]) << 32) |
Expand All @@ -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;
Expand Down
22 changes: 0 additions & 22 deletions src/log.cpp

This file was deleted.

0 comments on commit 83089af

Please sign in to comment.