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.

69 lines
2.1 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
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. #define LoggerFactory iflytop::core::SpdLoggerFactory::Instance()
  35. class SpdLoggerFactory {
  36. SpdLoggerFactory() {};
  37. std::mutex createLogger_lock;
  38. atomic_bool initializeLogger = {false};
  39. set<string> s_loggerNames;
  40. public:
  41. static SpdLoggerFactory &Instance() {
  42. static SpdLoggerFactory factory;
  43. return factory;
  44. }
  45. void initialize();
  46. shared_ptr<logger> createLogger(string loggerName);
  47. set<string> loggerNames();
  48. shared_ptr<logger> createRotatingFileLogger(const std::string &logger_name, size_t max_file_size = 5 * 1024 * 1024 /*5M*/, size_t max_files = 3,
  49. bool bindTerminal = true, bool bindDebug = true, bool bindInfo = true);
  50. sink_ptr getSink(string name);
  51. private:
  52. void parseSphLogConfig(string path);
  53. };
  54. } // namespace core
  55. } // namespace iflytop