#include "Log.h" #include "Constant.h" #include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/stdout_sinks.h" #include "spdlog/spdlog.h" #include #include #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO std::shared_ptr Log::logger = nullptr; bool Log::isInit = false; Log::Log() { } /** * @brief 初始化logger */ void Log::init() { std::vector sinks; // 用于将日志输出到控制台 auto console_sink = std::make_shared(); // 用于将日志按日期保存到文件中 auto daily_sink = std::make_shared(Constant::LogPath, 0, 1, false, 50); sinks.push_back(console_sink); sinks.push_back(daily_sink); logger = std::make_shared("daily_logger", sinks.begin(), sinks.end()); logger->set_pattern("[%Y/%m/%d %H:%M:%S] [%l] [thread:%t] [%s:%#] %v"); logger->flush_on(spdlog::level::info); spdlog::register_logger(logger); isInit = true; }