You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

5 months ago
  1. //
  2. // Created by zhaohe on 19-5-31.
  3. //
  4. #pragma once
  5. #include <fstream>
  6. #include <iostream>
  7. #include <list>
  8. #include <map>
  9. #include <memory>
  10. #include <set>
  11. #include <sstream>
  12. #include <string>
  13. #include <vector>
  14. //
  15. #include "spdlog/spdlog.h"
  16. //
  17. #include "spdlog/sinks/basic_file_sink.h"
  18. #include "spdlog/sinks/daily_file_sink.h"
  19. #include "spdlog/sinks/rotating_file_sink.h"
  20. #include "spdlog/sinks/stdout_color_sinks.h"
  21. namespace iflytop {
  22. namespace core {
  23. using namespace std;
  24. using namespace spdlog;
  25. typedef shared_ptr<spdlog::logger> logger_t;
  26. #define ENABLE_LOGGER(loggerName) \
  27. public: \
  28. iflytop::core::logger_t logger = iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName); \
  29. \
  30. private:
  31. #define CREATE_LOGGER(loggerName) iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName)
  32. #define GET_LOGGER(loggerName) iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName)
  33. class SpdLoggerFactory {
  34. SpdLoggerFactory() {};
  35. std::mutex createLogger_lock;
  36. atomic_bool initializeLogger = {false};
  37. set<string> s_loggerNames;
  38. public:
  39. static SpdLoggerFactory& Instance() {
  40. static SpdLoggerFactory factory;
  41. return factory;
  42. }
  43. shared_ptr<logger> createLogger(string loggerName);
  44. set<string> loggerNames();
  45. private:
  46. void parseSphLogConfig(string path);
  47. };
  48. } // namespace core
  49. } // namespace iflytop