| 18 | #include "util/stringutil.h" |
| 19 | |
| 20 | void highsOpenLogFile(HighsLogOptions& log_options, |
| 21 | std::vector<OptionRecord*>& option_records, |
| 22 | const std::string& log_file) { |
| 23 | HighsInt index; |
| 24 | OptionStatus status = |
| 25 | getOptionIndex(log_options, "log_file", option_records, index); |
| 26 | assert(status == OptionStatus::kOk); |
| 27 | if (log_options.log_stream != nullptr) { |
| 28 | // Current log file stream is not null, so flush and close it |
| 29 | fflush(log_options.log_stream); |
| 30 | fclose(log_options.log_stream); |
| 31 | // Set the stream to null to give a test whether it has been |
| 32 | // closed (and avoid trying to close it again which causes an |
| 33 | // error) |
| 34 | log_options.log_stream = nullptr; |
| 35 | } |
| 36 | assert(!log_options.log_stream); |
| 37 | // If new log file name is not empty, open it, appending if possible |
| 38 | // |
| 39 | // If fopen fails then it returns nullptr, so log_file is open for |
| 40 | // writing or nullptr |
| 41 | if (log_file.compare("")) |
| 42 | log_options.log_stream = fopen(log_file.c_str(), "a"); |
| 43 | OptionRecordString& option = *(OptionRecordString*)option_records[index]; |
| 44 | option.assignvalue(log_file); |
| 45 | } |
| 46 | |
| 47 | static std::string optionEntryTypeToString(const HighsOptionType type) { |
| 48 | if (type == HighsOptionType::kBool) { |
no test coverage detected