enum class LogLevel {HIGH, MEDIUM, LOW};
class Logger {
void SetLevel(LogLevel level);
void Log(string msg, LogLevel level);
}
void SectorProduce(int x, int y){
cout << "Producing in sector " << x << ", " << y << endl;
return;
}
void SectorProduce(int x, int y, Logger & logger){
string msg;
msg = "Producing in sector " + to_string(x) + ", " + to_string(y) + "\n";
logger.Log(msg, LogLevel::LOW);
return;
}
<sstream>
stringstream
.str() returns the string currently stored in the stream.
.str(string) sets the string currently stored in the stream.
void SectorProduce(int x, int y, Logger & logger){
stringstream output;
output << "Producing in sector " << x << ", " << y << endl;
logger.Log(output.str(), LogLevel::LOW);
// not required but I wanted to show this here.
output.str("");
return;
}
this variable either.
Logger::Instance()
Logger(const Logger &) = delete;
Log(string msg, LogLevel level = LogLevel::LOW);