Load Balancer Simulation
A simulation of a load balancer with dynamic server scaling in C++
Loading...
Searching...
No Matches
Logger Class Reference

Static logger that writes to both console and a log file. More...

#include <Logger.h>

Static Public Member Functions

static bool init (const std::string &filename)
 Initialize the logger with an output file.
static void close ()
 Close the log file.
static void log (const std::string &message)
 Write a message to both console and log file.
static bool isOpen ()
 Check if the log file is currently open.

Static Private Member Functions

static std::string stripAnsi (const std::string &str)
 Remove ANSI escape sequences from a string.

Static Private Attributes

static std::ofstream logFile_

Detailed Description

Static logger that writes to both console and a log file.

ANSI color codes are preserved for console output but stripped when writing to the log file.

Definition at line 19 of file Logger.h.

Member Function Documentation

◆ close()

void Logger::close ( )
static

Close the log file.

Definition at line 22 of file Logger.cpp.

Referenced by main().

◆ init()

bool Logger::init ( const std::string & filename)
static

Initialize the logger with an output file.

Initialize logger with output file.

Parameters
filenamePath to the log file
Returns
true if file opened successfully, false otherwise

Definition at line 13 of file Logger.cpp.

Referenced by main().

◆ isOpen()

bool Logger::isOpen ( )
inlinestatic

Check if the log file is currently open.

Returns
true if log file is open, false otherwise

Definition at line 45 of file Logger.h.

◆ log()

void Logger::log ( const std::string & message)
static

Write a message to both console and log file.

Write message to console and log file.

ANSI escape codes are stripped when writing to the file.

Parameters
messageThe message to log

Definition at line 36 of file Logger.cpp.

Referenced by LoadBalancer::log(), main(), LoadBalancer::printSummary(), and LoadBalancer::run().

◆ stripAnsi()

std::string Logger::stripAnsi ( const std::string & str)
staticprivate

Remove ANSI escape sequences from a string.

Remove ANSI escape sequences from string.

Parameters
strThe string to strip
Returns
String with ANSI codes removed

Definition at line 29 of file Logger.cpp.

Referenced by log().

Member Data Documentation

◆ logFile_

std::ofstream Logger::logFile_
staticprivate

Output stream for the log file

Definition at line 48 of file Logger.h.

Referenced by close(), init(), isOpen(), and log().


The documentation for this class was generated from the following files: