about summary refs log tree commit diff stats
path: root/archive/2025/summer/bsc_karidas/include/Logger.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'archive/2025/summer/bsc_karidas/include/Logger.hpp')
-rw-r--r--archive/2025/summer/bsc_karidas/include/Logger.hpp59
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