123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #pragma once
- #include <string>
- #include <spdlog/spdlog.h>
- #include "Format.h"
- #include "CSingletonBase.h"
- struct LogConfiguration
- {
- int sink_v = 2;
- int level_v = 0;
- std::string fileOut_v = "./log/StitchingServer.log";
- std::string pattern_v = "[%Y-%m-%d %H:%M:%S:%f] %n [%P-%t] [%l] %v";
- bool FromFile(std::string file_path);
- };
- class LogOutput
- {
- public:
- LogOutput(std::string instance, LogConfiguration LogConfig);
- LogOutput();
- ~LogOutput();
- spdlog::logger *log_sink{nullptr};
- bool E_File(bool isOpen, std::string FileName);
- bool W_File(bool isOpen, std::string FileName);
- void InitLog(std::string instance, LogConfiguration LogConfig);
- };
- namespace OmniLoger
- {
- class CLoger : public LogOutput, public CSingletonBase<CLoger>
- {
- };
- };
- #define LOG_INIT(logPath, LogConfig) OmniLoger::CLoger::get_instance().InitLog(logPath, LogConfig)
- #define LOG_INFO(...) \
- if (OmniLoger::CLoger::get_instance().log_sink != nullptr) \
- OmniLoger::CLoger::get_instance().log_sink->info(__VA_ARGS__)
- #define LOG_WARN(...) \
- if (OmniLoger::CLoger::get_instance().log_sink != nullptr) \
- OmniLoger::CLoger::get_instance().log_sink->warn(__VA_ARGS__)
- #define LOG_ERROR(...) \
- if (OmniLoger::CLoger::get_instance().log_sink != nullptr) \
- OmniLoger::CLoger::get_instance().log_sink->error(__VA_ARGS__)
|