loger.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // // ******************************************************************
  2. // // /\ /| @File Loger.h
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-05-16
  6. // // / \\ @Modified 2024-06-24
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #pragma once
  10. #include <iostream>
  11. #include <fstream>
  12. #include <mutex>
  13. #include <filesystem>
  14. #include <string>
  15. #include <chrono>
  16. #include <cstdarg>
  17. #include <iomanip>
  18. #include <sstream>
  19. #include <cstdlib> // 对于std::put_time的tm结构体定义
  20. #include "../BaseEnums/loger_enums.h"
  21. namespace Fs = std::filesystem;
  22. namespace Protocol
  23. {
  24. class Loger
  25. {
  26. public:
  27. Loger();
  28. static void Log(const std::string& message);
  29. ~Loger();
  30. inline static auto logLevel = LogLevel::All;
  31. private:
  32. std::string logPath_;
  33. std::string logFileName_; // The full path and filename of the log file.
  34. std::ofstream logFile_;
  35. static std::mutex instanceMutex_;
  36. static Loger instance_;
  37. Loger(const Loger&) = delete;
  38. Loger& operator=(const Loger&) = delete;
  39. };
  40. void WriteLog(LogLevel level, const char* format, ...);
  41. }