Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1
6
7#ifndef LOGGER_H
8#define LOGGER_H
9
10#include <fstream>
11#include <string>
12
27
40class Logger {
41public:
47 Logger(bool verbose, bool useColor);
48
54 bool openEventFile(const std::string& path);
55
57 bool verbose() const;
58
66 void log(LogCategory category, unsigned long cycle, const std::string& source,
67 const std::string& message);
68
75 std::string colorize(LogCategory category, const std::string& text) const;
76
77private:
78 static const char* label(LogCategory category);
79 static const char* color(LogCategory category);
80
81 bool verbose_;
82 bool useColor_;
83 std::ofstream eventFile_;
84};
85
86#endif
LogCategory
Kind of event being logged; selects the color and whether quiet mode shows it.
Definition Logger.h:16
@ Assign
A queued request was dispatched to a server.
Definition Logger.h:18
@ Info
General information such as start-up messages.
Definition Logger.h:25
@ Arrival
A request entered the queue.
Definition Logger.h:17
@ ScaleDown
A server was removed or marked for retirement.
Definition Logger.h:23
@ Complete
A server finished a request.
Definition Logger.h:19
@ Discard
The queue was full and a request was dropped.
Definition Logger.h:21
@ Reject
The firewall blocked a request.
Definition Logger.h:20
@ Status
Periodic queue and server status line.
Definition Logger.h:24
@ ScaleUp
A server was added or returned to service.
Definition Logger.h:22
bool openEventFile(const std::string &path)
Copies events to a file in addition to the console.
Definition Logger.cpp:22
bool verbose() const
Definition Logger.cpp:27
void log(LogCategory category, unsigned long cycle, const std::string &source, const std::string &message)
Logs one event.
Definition Logger.cpp:68
Logger(bool verbose, bool useColor)
Creates a logger.
Definition Logger.cpp:19
std::string colorize(LogCategory category, const std::string &text) const
Wraps text in an ANSI color for console output when colors are enabled.
Definition Logger.cpp:61