diff options
| author | Dimitris <dimstav23@gmail.com> | 2025-07-15 15:11:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 15:11:36 +0200 |
| commit | 73e505f04d17eba36c41fce7b48bc4d6884b8fd0 (patch) | |
| tree | 44b5f4627309a48d6f22b54bb2ad9a2976e8601b /archive/2025/summer/bsc_karidas/include/Logger.hpp | |
| parent | ca92e7ad181a02890496872012ecc6c1d08b1658 (diff) | |
| parent | d8c365681a41961ebe2daea5701a4d56f5400d1d (diff) | |
| download | research-work-archive-artifacts-73e505f04d17eba36c41fce7b48bc4d6884b8fd0.tar.gz research-work-archive-artifacts-73e505f04d17eba36c41fce7b48bc4d6884b8fd0.zip | |
Merge pull request #6 from chriskari/upload-artifacts
Add bsc_karidas
Diffstat (limited to 'archive/2025/summer/bsc_karidas/include/Logger.hpp')
| -rw-r--r-- | archive/2025/summer/bsc_karidas/include/Logger.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/archive/2025/summer/bsc_karidas/include/Logger.hpp b/archive/2025/summer/bsc_karidas/include/Logger.hpp new file mode 100644 index 000000000..d4119d364 --- /dev/null +++ b/archive/2025/summer/bsc_karidas/include/Logger.hpp @@ -0,0 +1,59 @@ +#ifndef LOGGER_HPP +#define LOGGER_HPP + +#include "LogEntry.hpp" +#include "BufferQueue.hpp" +#include "QueueItem.hpp" +#include <string> +#include <chrono> +#include <memory> +#include <vector> +#include <shared_mutex> +#include <functional> +#include <optional> + +class Logger +{ + friend class LoggerTest; + +public: + static Logger &getInstance(); + + bool initialize(std::shared_ptr<BufferQueue> queue, + std::chrono::milliseconds appendTimeout = std::chrono::milliseconds::max()); + + BufferQueue::ProducerToken createProducerToken(); + bool append(LogEntry entry, + BufferQueue::ProducerToken &token, + const std::optional<std::string> &filename = std::nullopt); + bool appendBatch(std::vector<LogEntry> entries, + BufferQueue::ProducerToken &token, + const std::optional<std::string> &filename = std::nullopt); + + bool exportLogs(const std::string &outputPath, + std::chrono::system_clock::time_point fromTimestamp = std::chrono::system_clock::time_point(), + std::chrono::system_clock::time_point toTimestamp = std::chrono::system_clock::time_point()); + + bool reset(); + + ~Logger(); + +private: + Logger(); + Logger(const Logger &) = delete; + Logger &operator=(const Logger &) = delete; + // Singleton instance + static std::unique_ptr<Logger> s_instance; + static std::mutex s_instanceMutex; + + std::shared_ptr<BufferQueue> m_logQueue; + std::chrono::milliseconds m_appendTimeout; + + // State tracking + bool m_initialized; + + // Helper to report errors + void reportError(const std::string &message); +}; + +#endif \ No newline at end of file |