diff --git a/src/unlocker/log-sink-file.h b/src/unlocker/log-sink-file.h new file mode 100644 index 0000000..54392cf --- /dev/null +++ b/src/unlocker/log-sink-file.h @@ -0,0 +1,48 @@ +#pragma once + +#include + +#include +#include +#include +#include + +#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 lock(_mutex); + if (_file.is_open()) + { + _file << "[" << loggerName << "] [" + << seallib::getLogTypeName(type) << "] " + << msg << std::endl; + } + } + + static std::shared_ptr getSharedInstance() + { + static std::shared_ptr instance = std::make_shared("hex-unlocked.log"); + return instance; + } + + private: + std::ofstream _file; + std::mutex _mutex; +};