Skip to content

Commit

Permalink
add MathloggerDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Nov 20, 2023
1 parent 4cfd573 commit d3527c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/cpp/benders/logger/MathLogger.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "logger/MathLogger.h"

#include <iomanip>
#include <iostream>
#include <sstream>

#include "LoggerUtils.h"
Expand Down Expand Up @@ -36,4 +35,16 @@ MathLoggerFile::MathLoggerFile(const std::filesystem::path &filename)
std::cerr << PrefixMessage(LogUtils::LOGLEVEL::ERR, data.CONTEXT)
<< "Invalid file name passed as parameter" << std::endl;
}
}

void MathLoggerDriver::write_header() {
for (auto logger : math_loggers_) {
logger->write_header();
}
}

void MathLoggerDriver::add_logger(MathLogger* logger) {
if (logger) {
math_loggers_.push_back(logger);
}
}
17 changes: 17 additions & 0 deletions src/cpp/benders/logger/include/logger/MathLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>

struct MathLoggerData {
int iteration;
Expand Down Expand Up @@ -62,4 +64,19 @@ class MathLoggerFile : public MathLogger {

private:
std::ofstream file_stream_;
};

class MathLoggerOstream : public MathLogger {
public:
explicit MathLoggerOstream() : MathLogger(&std::cout) {}
};

class MathLoggerDriver {
public:
MathLoggerDriver() = default;
void write_header();
void MathLoggerDriver::add_logger(MathLogger* logger);

private:
std::list<MathLogger*> math_loggers_;
};

0 comments on commit d3527c4

Please sign in to comment.