// logger.hpp
#pragma once

#include <chrono>
#include <ctime>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>

enum class LogLevel
{
    INFO,
    WARN,
    ERROR
};

class Logger
{
   public:
    static void init(const std::string& log_dir, int keep_days = 30);

    static void log(LogLevel level, const std::string& msg);

    static std::string get_current_time_utc8();

   private:
    static std::ofstream log_file;
    static std::string log_directory;
    static std::string current_date;
    static std::string current_filename;
    static int keep_days_;

    static std::string get_time_string();
    static std::string get_today_date();
    static void open_log_file();
    static void check_date_rollover();
    static void cleanup_old_logs();
};

// 简化宏
#define LOG_INFO(msg) Logger::log(LogLevel::INFO, msg)
#define LOG_WARN(msg) Logger::log(LogLevel::WARN, msg)
#define LOG_ERROR(msg) Logger::log(LogLevel::ERROR, msg)
