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.

62 lines
1.7 KiB

4 months ago
4 months ago
4 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. #define GET_SINK(sinkName) iflytop::core::SpdLoggerFactory::Instance().getSink(sinkName)
  34. class SpdLoggerFactory {
  35. SpdLoggerFactory() {};
  36. std::mutex createLogger_lock;
  37. atomic_bool initializeLogger = {false};
  38. set<string> s_loggerNames;
  39. public:
  40. static SpdLoggerFactory& Instance() {
  41. static SpdLoggerFactory factory;
  42. return factory;
  43. }
  44. shared_ptr<logger> createLogger(string loggerName);
  45. set<string> loggerNames();
  46. sink_ptr getSink(string name);
  47. private:
  48. void parseSphLogConfig(string path);
  49. };
  50. } // namespace core
  51. } // namespace iflytop