A singleton that subscribes to the AlertManager and writes alert events to a per-session log file (and the console) from a background worker thread.
More...
#include <Logger.h>
|
| void | Initialize (const std::string &logDirectory="") |
| | Opens a new, per-session timestamped log file inside the given directory (created if it doesn't exist, defaulting to ~/rumpi_logs), prunes old logs, and starts the worker thread. More...
|
| |
| void | Shutdown () |
| | Signals shutdown, wakes the worker thread to drain any remaining events, joins it, and closes the log file. More...
|
| |
| const std::string & | GetLogFilePath () const |
| | Gets the path the logger was initialized with (empty until Initialize() has run). More...
|
| |
| 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 not running. More...
|
| |
| | Logger (const Logger &)=delete |
| |
| Logger & | operator= (const Logger &)=delete |
| |
|
| | Logger () |
| | Builds the logger in the stopped state. More...
|
| |
| virtual | ~Logger () |
| | Destroys the logger, shutting it down first. More...
|
| |
| void | ProcessQueue () |
| | Worker loop: waits for queued events (or shutdown), drains them in one swap, writes each outside the lock, and flushes the log per batch. More...
|
| |
| 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 console. More...
|
| |
| void | CleanUpOldLogs (const std::string &directory, const size_t maxFilesToKeep) |
| | Deletes the oldest session log files in the given directory, keeping at most maxFilesToKeep. More...
|
| |
A singleton that subscribes to the AlertManager and writes alert events to a per-session log file (and the console) from a background worker thread.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
◆ Logger() [1/2]
| RumPi::Logger::Logger |
( |
| ) |
|
|
private |
Builds the logger in the stopped state.
Private so only GetInstance can construct it.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
◆ ~Logger()
| RumPi::Logger::~Logger |
( |
| ) |
|
|
privatevirtual |
Destroys the logger, shutting it down first.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
◆ Logger() [2/2]
| RumPi::Logger::Logger |
( |
const Logger & |
| ) |
|
|
delete |
◆ CleanUpOldLogs()
| void RumPi::Logger::CleanUpOldLogs |
( |
const std::string & |
directory, |
|
|
const size_t |
maxFilesToKeep |
|
) |
| |
|
private |
Deletes the oldest session log files in the given directory, keeping at most maxFilesToKeep.
Called on startup so ~/rumpi_logs doesn't grow without bound.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
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
constexpr size_t RUMPI_MAX_LOG_FILES_TO_KEEP
Definition: Common.h:62
- Parameters
-
| [in] | directory | The directory to prune. |
| [in] | maxFilesToKeep | The maximum number of session log files to keep. |
◆ GetInstance()
| Logger & RumPi::Logger::GetInstance |
( |
| ) |
|
|
static |
Gets the singleton instance, constructing it thread-safely on first call.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
Logger()
Builds the logger in the stopped state.
Definition: Logger.cpp:21
static Logger & GetInstance()
Gets the singleton instance, constructing it thread-safely on first call.
Definition: Logger.cpp:224
- Returns
- The single Logger instance.
◆ GetLogFilePath()
| const std::string & RumPi::Logger::GetLogFilePath |
( |
| ) |
const |
Gets the path the logger was initialized with (empty until Initialize() has run).
Handy for a client that wants to reveal or open the log file.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
const std::string & GetLogFilePath() const
Gets the path the logger was initialized with (empty until Initialize() has run).
Definition: Logger.cpp:172
- Returns
- The current log file path, or empty if not yet initialized.
◆ HandleAlert()
| void RumPi::Logger::HandleAlert |
( |
const AlertEvent & |
theAlertEvent | ) |
|
Queues an alert event for the worker thread to write and wakes it; writes to stderr if the logger is not running.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
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
- Parameters
-
| [in] | theAlertEvent | The alert event to queue. |
◆ Initialize()
| void RumPi::Logger::Initialize |
( |
const std::string & |
logDirectory = "" | ) |
|
Opens a new, per-session timestamped log file inside the given directory (created if it doesn't exist, defaulting to ~/rumpi_logs), prunes old logs, and starts the worker thread.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
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
- Parameters
-
| [in] | logDirectory | The directory to write logs to, or empty to default to ~/rumpi_logs. |
◆ operator=()
◆ ProcessQueue()
| void RumPi::Logger::ProcessQueue |
( |
| ) |
|
|
private |
Worker loop: waits for queued events (or shutdown), drains them in one swap, writes each outside the lock, and flushes the log per batch.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
◆ Shutdown()
| void RumPi::Logger::Shutdown |
( |
| ) |
|
Signals shutdown, wakes the worker thread to drain any remaining events, joins it, and closes the log file.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
void Shutdown()
Signals shutdown, wakes the worker thread to drain any remaining events, joins it,...
Definition: Logger.cpp:187
◆ WriteEvent()
| void RumPi::Logger::WriteEvent |
( |
const AlertEvent & |
theAlertEvent | ) |
|
|
private |
Writes a single alert event as a timestamped line to the log file (if open) and echoes it to the console.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
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
- Parameters
-
| [in] | theAlertEvent | The alert event to write. |
◆ myEventQueue
| std::queue<AlertEvent> RumPi::Logger::myEventQueue |
|
protected |
Alert events waiting to be written.
◆ myIsRunning
| std::atomic<bool> RumPi::Logger::myIsRunning |
|
protected |
True while the logger is initialized and its worker is running.
◆ myLogFile
| std::ofstream RumPi::Logger::myLogFile |
|
protected |
The open log file stream.
◆ myLogFilePath
| std::string RumPi::Logger::myLogFilePath |
|
protected |
The path of the current session's log file.
◆ myQueueCondition
| std::condition_variable RumPi::Logger::myQueueCondition |
|
protected |
Signals the worker thread that events are queued (or shutdown).
◆ myQueueMutex
| std::mutex RumPi::Logger::myQueueMutex |
|
protected |
◆ myWorkerThread
| std::thread RumPi::Logger::myWorkerThread |
|
protected |
The background thread that drains the queue to the log.
The documentation for this class was generated from the following files: