#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
// #include <spdlog/sinks/daily_file_sink.h>
#include "sys_util.h"
#include "daily_and_size_sink.h"

namespace zsy
{
    std::shared_ptr<spdlog::logger> getLogger()
    {
        static std::shared_ptr<spdlog::logger> logger = []
        {
            // const auto file_sink = std::make_shared<spdlog::sinks::daily_file_format_sink_mt>(SysUtil::WORK_DIR + "\\logs\\deviceAccessLayer.log", 0, 0);
            auto file_sink = std::make_shared<DailyAndSizeSink>(
                SysUtil::WORK_DIR + "\\logs\\deviceAccessLayer.log",
                100 * 1024 * 1024,
                15
            );
            file_sink->set_level(spdlog::level::info);
            file_sink->set_pattern("%Y-%m-%d %H:%M:%S.%e %=7l %=10t %-40s [%-64! %10#]: %v");

            const auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
            console_sink->set_level(spdlog::level::info);
            console_sink->set_pattern("%Y-%m-%d %H:%M:%S.%e %=7l %=10t %-40s [%-64! %10#]: %v");

            spdlog::sinks_init_list sinks = {console_sink, file_sink};
            auto logger = std::make_shared<spdlog::logger>("zsy", sinks);
            logger->flush_on(spdlog::level::info);
            spdlog::set_default_logger(logger);
            return logger;
        }();
        return logger;
    }
}
