91 void CleanUpOldLogs(
const std::string& directory,
const size_t maxFilesToKeep);
107 void Initialize(
const std::string& logDirectory =
"");
A single alert event: a metric crossing (or recovering from) a threshold, with the reading that trigg...
Definition: AlertEvent.h:13
A singleton that subscribes to the AlertManager and writes alert events to a per-session log file (an...
Definition: Logger.h:15
std::condition_variable myQueueCondition
Signals the worker thread that events are queued (or shutdown).
Definition: Logger.h:21
std::atomic< bool > myIsRunning
True while the logger is initialized and its worker is running.
Definition: Logger.h:23
const std::string & GetLogFilePath() const
Gets the path the logger was initialized with (empty until Initialize() has run).
Definition: Logger.cpp:172
std::mutex myQueueMutex
Guards the event queue.
Definition: Logger.h:20
std::thread myWorkerThread
The background thread that drains the queue to the log.
Definition: Logger.h:22
Logger()
Builds the logger in the stopped state.
Definition: Logger.cpp:21
void CleanUpOldLogs(const std::string &directory, const size_t maxFilesToKeep)
Deletes the oldest session log files in the given directory, keeping at most maxFilesToKeep.
Definition: Logger.cpp:125
Logger & operator=(const Logger &)=delete
std::string myLogFilePath
The path of the current session's log file.
Definition: Logger.h:17
std::ofstream myLogFile
The open log file stream.
Definition: Logger.h:18
void WriteEvent(const AlertEvent &theAlertEvent)
Writes a single alert event as a timestamped line to the log file (if open) and echoes it to the cons...
Definition: Logger.cpp:291
void Initialize(const std::string &logDirectory="")
Opens a new, per-session timestamped log file inside the given directory (created if it doesn't exist...
Definition: Logger.cpp:54
void HandleAlert(const AlertEvent &theAlertEvent)
Queues an alert event for the worker thread to write and wakes it; writes to stderr if the logger is ...
Definition: Logger.cpp:321
virtual ~Logger()
Destroys the logger, shutting it down first.
Definition: Logger.cpp:36
void Shutdown()
Signals shutdown, wakes the worker thread to drain any remaining events, joins it,...
Definition: Logger.cpp:187
Logger(const Logger &)=delete
void ProcessQueue()
Worker loop: waits for queued events (or shutdown), drains them in one swap, writes each outside the ...
Definition: Logger.cpp:243
std::queue< AlertEvent > myEventQueue
Alert events waiting to be written.
Definition: Logger.h:19
static Logger & GetInstance()
Gets the singleton instance, constructing it thread-safely on first call.
Definition: Logger.cpp:224
RumPi is the library's top-level facade.
Definition: AlertManager.h:6