feat: add file log sink

This commit is contained in:
2026-06-20 08:04:36 -03:00
parent c0b710d6f7
commit df9ad4fc70
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include <seallib/log.h>
#include <fstream>
#include <string>
#include <mutex>
#include <memory>
#include "utils.h"
using namespace seallib;
class FileSink : public ILogSink
{
public:
FileSink(const std::string& filename)
{
_file.open(utils::getExePath() + filename, std::ios::out | std::ios::app);
}
~FileSink()
{
if (_file.is_open())
_file.close();
}
virtual void receiveLog(LogType type, std::string_view loggerName, std::string_view msg) override
{
std::lock_guard<std::mutex> lock(_mutex);
if (_file.is_open())
{
_file << "[" << loggerName << "] ["
<< seallib::getLogTypeName(type) << "] "
<< msg << std::endl;
}
}
static std::shared_ptr<FileSink> getSharedInstance()
{
static std::shared_ptr<FileSink> instance = std::make_shared<FileSink>("hex-unlocked.log");
return instance;
}
private:
std::ofstream _file;
std::mutex _mutex;
};