20 this->initialize(file_name, cout_write);
23 void initialize(
const std::string& file_name,
bool cout_write=
false)
const
25 log_file_.open(file_name);
26 if (log_file_.fail()) {
27 throw std::runtime_error(
"[SimulationLogger] Unable to open the file '" + file_name +
"' for writing.");
30 cout_write_ = cout_write;
31 file_name_ = file_name;
34 bool is_initialized()
const {
return log_file_.is_open(); }
43 if (file_name_ ==
"") {
57 const SimulationLogger& operator<< (
const std::vector<std::string>& values)
const
59 if (file_name_ ==
"") {
64 for (
const auto& value : values) {
67 if (cout_write_) std::cout <<
", ";
70 if (cout_write_) std::cout << value;
77 const SimulationLogger& operator<<(std::ostream&(*value)(std::ostream& o))
const
79 if (file_name_ ==
"") {
94 template<
typename... Args>
96 if (file_name_ ==
"")
return *
this;
99 ((first ? (first =
false, (*
this << args)) : (*
this <<
' ' << args)), ...);
109 mutable bool cout_write_ =
false;
110 mutable bool initialized_ =
false;
111 mutable std::string file_name_;
112 mutable std::ofstream log_file_;
const SimulationLogger & log_message(const Args &... args) const
Log a message with automatic space separation.
Definition SimulationLogger.h:95