Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
Loading...
Searching...
No Matches
Logger Class Reference

Writes simulation events to the console and, optionally, to a file. More...

#include <Logger.h>

Public Member Functions

 Logger (bool verbose, bool useColor)
 Creates a logger.
bool openEventFile (const std::string &path)
 Copies events to a file in addition to the console.
bool verbose () const
void log (LogCategory category, unsigned long cycle, const std::string &source, const std::string &message)
 Logs one event.
std::string colorize (LogCategory category, const std::string &text) const
 Wraps text in an ANSI color for console output when colors are enabled.

Detailed Description

Writes simulation events to the console and, optionally, to a file.

Two modes are supported:

  • Verbose mode prints every event (arrivals, assignments, completions, rejections and scaling) in color and copies them to the event file.
  • Quiet mode prints only periodic status lines and information messages, so a 100,000-cycle run stays readable; the full summary is written at the end.

ANSI colors are used only when standard output is a terminal and color has not been disabled. Files never contain color codes.

Definition at line 40 of file Logger.h.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( bool verbose,
bool useColor )

Creates a logger.

Parameters
verboseTrue to print every event; false for quiet mode.
useColorTrue to allow ANSI colors on a terminal.

Definition at line 19 of file Logger.cpp.

Member Function Documentation

◆ openEventFile()

bool Logger::openEventFile ( const std::string & path)

Copies events to a file in addition to the console.

Parameters
pathFile to create or overwrite.
Returns
False if the file could not be opened.

Definition at line 22 of file Logger.cpp.

◆ verbose()

bool Logger::verbose ( ) const
Returns
True in verbose mode.

Definition at line 27 of file Logger.cpp.

◆ log()

void Logger::log ( LogCategory category,
unsigned long cycle,
const std::string & source,
const std::string & message )

Logs one event.

Parameters
categoryEvent kind; Arrival/Assign/Complete/Reject/Discard/Scale events appear only in verbose mode.
cycleClock cycle of the event.
sourceName of the load balancer reporting the event.
messageEvent text.

Definition at line 68 of file Logger.cpp.

◆ colorize()

std::string Logger::colorize ( LogCategory category,
const std::string & text ) const

Wraps text in an ANSI color for console output when colors are enabled.

Parameters
categoryCategory whose color to use.
textText to color.
Returns
Colored text, or the original text when colors are off.

Definition at line 61 of file Logger.cpp.


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