#pragma once
#include <fstream>
#include <iostream>
#include <mutex>
#include <string>

namespace secondvoice {

class Logger {
public:
    static Logger& getInstance() {
        static Logger instance;
        return instance;
    }

    void log(const std::string& message) {
        std::lock_guard<std::mutex> lock(mutex_);
        std::cout << message << std::endl;
        if (file_.is_open()) {
            file_ << message << std::endl;
            file_.flush();
        }
    }

private:
    Logger() {
        file_.open("secondvoice_debug.log", std::ios::out | std::ios::trunc);
    }

    ~Logger() {
        if (file_.is_open()) {
            file_.close();
        }
    }

    std::ofstream file_;
    std::mutex mutex_;
};

#define LOG(msg) secondvoice::Logger::getInstance().log(msg)

} // namespace secondvoice
