LogOutput.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include <string>
  3. #include <spdlog/spdlog.h>
  4. #include "Format.h"
  5. #include "CSingletonBase.h"
  6. struct LogConfiguration
  7. {
  8. int sink_v = 2;
  9. int level_v = 0;
  10. std::string fileOut_v = "./log/StitchingServer.log";
  11. std::string pattern_v = "[%Y-%m-%d %H:%M:%S:%f] %n [%P-%t] [%l] %v";
  12. bool FromFile(std::string file_path);
  13. };
  14. class LogOutput
  15. {
  16. public:
  17. LogOutput(std::string instance, LogConfiguration LogConfig);
  18. LogOutput();
  19. ~LogOutput();
  20. spdlog::logger *log_sink{nullptr};
  21. bool E_File(bool isOpen, std::string FileName);
  22. bool W_File(bool isOpen, std::string FileName);
  23. void InitLog(std::string instance, LogConfiguration LogConfig);
  24. };
  25. namespace OmniLoger
  26. {
  27. class CLoger : public LogOutput, public CSingletonBase<CLoger>
  28. {
  29. };
  30. };
  31. #define LOG_INIT(logPath, LogConfig) OmniLoger::CLoger::get_instance().InitLog(logPath, LogConfig)
  32. #define LOG_INFO(...) \
  33. if (OmniLoger::CLoger::get_instance().log_sink != nullptr) \
  34. OmniLoger::CLoger::get_instance().log_sink->info(__VA_ARGS__)
  35. #define LOG_WARN(...) \
  36. if (OmniLoger::CLoger::get_instance().log_sink != nullptr) \
  37. OmniLoger::CLoger::get_instance().log_sink->warn(__VA_ARGS__)
  38. #define LOG_ERROR(...) \
  39. if (OmniLoger::CLoger::get_instance().log_sink != nullptr) \
  40. OmniLoger::CLoger::get_instance().log_sink->error(__VA_ARGS__)