#pragma once #include "../Base/global_include.h" #include "spdlog/common.h" #include "spdlog/logger.h" #include #include #include #include void rotating_log(const std::string& fileName, const std::string& info, int size = 10 * 1024 * 1024, int num = 10); // 自带换行符 void pure_log(const std::string& path, const std::string& info, bool close_after_write = false); struct Log_Type { Log_Type() = default; explicit Log_Type(std::vector list); explicit Log_Type(std::vector> map); Log_Type(std::vector list, std::vector> map); Log_Type& append(std::string key); Log_Type& append(std::string key, std::string val); [[nodiscard]] std::string to_string() const; Log_Type& set(const std::string& key, std::string val); bool new_line = false; protected: std::vector list; std::vector> map; }; class BaseLogger { public: BaseLogger(const std::string& path, size_t byte_size, size_t piece_num); void c_debug(const std::string& func_pattern, const Log_Type& log_type, const std::string& content); void debug(const std::string& func_pattern, const Log_Type& log_type, const std::string& content); void error(const std::string& func_pattern, const Log_Type& log_type, const std::string& content); struct Log_Info{ bool console; spdlog::level::level_enum level; std::string func_pattern; Log_Type log_type; std::string content; }; void set_redirect(const std::function& t) { redirect = t; } static std::string to_log(const Log_Info& log_info); protected: std::string log_path; size_t byte_size; size_t piece_num; std::shared_ptr logger; std::function redirect = nullptr; void log_main(const Log_Info& log_info) const; }; class Base_Logger_Manager : public Psc::Singleton { public: Base_Logger_Manager(); Base_Logger_Manager& set_thread_num(size_t thread_num); Base_Logger_Manager& set_flush_seconds(size_t flush_seconds); Base_Logger_Manager& set_buffer_size(size_t buffer_size); void init() const; ~Base_Logger_Manager(); protected: size_t thread_num = 1; size_t flush_seconds = 3; size_t buffer_size = 8192 * 8; }; std::string get_current_date_string();