kunlang_video/include/logger.hpp
2025-11-13 14:24:34 +08:00

45 lines
928 B
C++

// 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);
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 std::string get_time_string();
static std::string get_today_date();
static void open_log_file();
static void check_date_rollover();
};
// 简化宏
#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)