From d3527c431c8c48f55cca37edd8cd22f62b33b37a Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 20 Nov 2023 15:20:15 +0100 Subject: [PATCH] add MathloggerDriver --- src/cpp/benders/logger/MathLogger.cpp | 13 ++++++++++++- .../benders/logger/include/logger/MathLogger.h | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cpp/benders/logger/MathLogger.cpp b/src/cpp/benders/logger/MathLogger.cpp index 66049b95f..35f1e970e 100644 --- a/src/cpp/benders/logger/MathLogger.cpp +++ b/src/cpp/benders/logger/MathLogger.cpp @@ -1,7 +1,6 @@ #include "logger/MathLogger.h" #include -#include #include #include "LoggerUtils.h" @@ -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); + } } \ No newline at end of file diff --git a/src/cpp/benders/logger/include/logger/MathLogger.h b/src/cpp/benders/logger/include/logger/MathLogger.h index c3267c9c1..6c2653d98 100644 --- a/src/cpp/benders/logger/include/logger/MathLogger.h +++ b/src/cpp/benders/logger/include/logger/MathLogger.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include struct MathLoggerData { int iteration; @@ -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 math_loggers_; }; \ No newline at end of file