diff --git a/Bin2CPP/Sources/Bin2CPP/main.cpp b/Bin2CPP/Sources/Bin2CPP/main.cpp index f5bc1c9..add0981 100644 --- a/Bin2CPP/Sources/Bin2CPP/main.cpp +++ b/Bin2CPP/Sources/Bin2CPP/main.cpp @@ -5,15 +5,13 @@ int main(int argc, char** argv) { - Bin2CPP::Singleton::Lifetime loggerLifetime; - CLI::App app {"Bin2CPP allows you to generate a C++ header containing the binary content of an input file"}; argv = app.ensure_utf8(argv); std::string input; - app.add_option("-f,--input", input, "The input file")->required(); + app.add_option("-f,--input", input, "The input file"); std::string output; - app.add_option("-o,--output", output, "The output file")->required(); + app.add_option("-o,--output", output, "The output file"); std::optional arrayType; app.add_option("--arrayType", arrayType, "The type of the array"); std::optional arrayInclude; @@ -22,9 +20,14 @@ int main(int argc, char** argv) app.add_option("--arrayName", arrayName, "The array name"); std::optional customNamespace; app.add_option("--namespace", customNamespace, "The namespace"); + bool verbose = false; + app.add_option("--verbose", verbose, "Activate logging"); CLI11_PARSE(app, argc, argv); + std::unique_ptr::Lifetime> loggerLifetime = + verbose ? std::make_unique::Lifetime>() : nullptr; + Bin2CPP::Generator generator(input); if (arrayType) { diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp index 519bb72..d9a3ab2 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp @@ -80,36 +80,48 @@ class Log #define BIN2CPP_LOG_INFO(fmt, ...) \ do \ { \ - if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ } \ } while (0) #define BIN2CPP_LOG_WARN(fmt, ...) \ do \ { \ - if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ } \ } while (0) #define BIN2CPP_LOG_ERROR(fmt, ...) \ do \ { \ - if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ } \ } while (0) #define BIN2CPP_LOG_FATAL(fmt, ...) \ do \ { \ - if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ } \ } while (0) #endif