A.R.G.U.S 2.1.0
Adaptive Real-Time Guardian for Unsafe Situations
Loading...
Searching...
No Matches
MetricsLogger.hpp
Go to the documentation of this file.
1
16#ifndef METRICS_LOGGER_HPP
17#define METRICS_LOGGER_HPP
18
19#include <string>
20#include <queue>
21#include <mutex>
22#include <thread>
23#include <condition_variable>
24#include <atomic>
25#include <fstream>
26#include <chrono>
27#include <iomanip>
28#include <sstream>
29
40private:
41 struct LogEntry {
42 std::string timestamp;
43 std::string category;
44 std::string message;
45 };
46
47 std::queue<LogEntry> logQueue;
48 std::mutex queueMutex;
49 std::condition_variable queueCV;
50 std::atomic<bool> running;
51 std::thread logThread;
52 std::ofstream logFile;
53
58
62 void processLogs();
63
68 std::string getCurrentTimestamp();
69
70public:
75 static MetricsLogger& getInstance();
76
80 MetricsLogger(const MetricsLogger&) = delete;
81
86
91
102 void logEvent(const std::string& category, const std::string& message);
103
107 void flush();
108};
109
110#endif // METRICS_LOGGER_HPP
Singleton logger with non-blocking, thread-safe operation.
~MetricsLogger()
Destructor - stops logging thread.
MetricsLogger(const MetricsLogger &)=delete
Deleted copy constructor (Singleton)
static MetricsLogger & getInstance()
Gets singleton instance.
void flush()
Flushes all pending logs (blocking - use only at shutdown)
MetricsLogger & operator=(const MetricsLogger &)=delete
Deleted assignment operator (Singleton)
void logEvent(const std::string &category, const std::string &message)
Logs an event (non-blocking, thread-safe)