MAiNGO
logger.h
Go to the documentation of this file.
1 /**********************************************************************************
2  * Copyright (c) 2019 Process Systems Engineering (AVT.SVT), RWTH Aachen University
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License 2.0 which is available at
6  * http://www.eclipse.org/legal/epl-2.0.
7  *
8  * SPDX-License-Identifier: EPL-2.0
9  *
10  * @file logger.h
11  *
12  * @brief File declaring the logger class which manages the printing of output
13  * and writing of files.
14  *
15  **********************************************************************************/
16 
17 #pragma once
18 
19 #include "MAiNGOdebug.h"
20 #include "returnCodes.h"
21 #include "settings.h"
22 
23 #include <iostream>
24 #include <map>
25 #include <queue>
26 #include <vector>
27 
28 
29 namespace maingo {
30 
31 
37  // The first name has to be 1 and the names have to be increasing (in numbering)
38  EPSILONA = 1,
92 };
93 
100 class Logger {
101 
102  public:
106  Logger(){};
107 
111  Logger(const Logger&) = default;
112 
116  Logger& operator=(const Logger&) = default;
117 
121  ~Logger() {}
122 
132  void print_message(const std::string& message, bool writeLog, VERB verbosityGiven, VERB verbosityNeeded, OUTSTREAM_VERB givenOutstreamVerbosity);
133 
140  void print_message_to_stream_only(const std::string& message, OUTSTREAM_VERB givenOutstreamVerbosity);
141 
147  void set_output_stream(std::ostream* outputStream);
148 
155  void create_log_file(bool writeLog, OUTSTREAM_VERB givenOutstreamVerbosity);
156 
166  void create_csv_files(bool pureMultistart, bool printEveryLocalSearch, unsigned int maxLocalSearches, const std::vector<double>& objectivesAtRoot, const std::vector<SUBSOLVER_RETCODE>& feasibleAtRoot);
167 
173  void write_all_lines_to_log(const std::string& errmsg = "");
174 
180  void write_all_iterations_to_csv(const std::string& errmsg = "");
181 
188  void save_settings_file_name(const std::string& fileName, bool fileFound);
189 
196  void save_setting(SETTING_NAMES settingName, const std::string& str);
197 
206  void print_settings(bool writeLog, VERB verbosityGiven, VERB verbosityNeeded, OUTSTREAM_VERB givenOutstreamVerbosity);
207 
211  void clear();
212 
217  std::queue<std::string> babLine;
218  std::queue<std::string> babLineCsv;
219  std::string logFileName;
220  std::string resFileName;
221  std::string csvIterationsName;
222  std::string csvGeneralName;
226  private:
231  std::ostream* _outStream = &std::cout;
232  unsigned int _nSettingFiles = 0;
233  std::map<int, std::string> _userSetSettings;
236 }; // end of class Logger
237 
238 
239 } // end namespace maingo
Definition: logger.h:40
std::ostream * _outStream
Definition: logger.h:231
Definition: logger.h:86
Definition: logger.h:78
void save_settings_file_name(const std::string &fileName, bool fileFound)
Function used for saving the names of setting files set by the user.
Definition: logger.cpp:174
Definition: logger.h:63
bool reachedMinNodeSize
Definition: logger.h:223
std::queue< std::string > babLine
Definition: logger.h:217
std::string csvGeneralName
Definition: logger.h:222
Definition: logger.h:59
Definition: logger.h:55
std::string logFileName
Definition: logger.h:219
Definition: logger.h:69
Definition: logger.h:46
Definition: logger.h:90
Definition: logger.h:39
Definition: logger.h:58
Definition: logger.h:74
Definition: logger.h:42
std::map< int, std::string > _userSetSettings
Definition: logger.h:233
void save_setting(SETTING_NAMES settingName, const std::string &str)
Function used for saving the user-set settings.
Definition: logger.cpp:197
Definition: logger.h:60
Logger()
Default constructor.
Definition: logger.h:106
Definition: logger.h:47
Definition: logger.h:49
Definition: logger.h:54
Definition: logger.h:57
SETTING_NAMES
Enum for representing the setting names and making the tracking of set settings easier.
Definition: logger.h:36
void write_all_lines_to_log(const std::string &errmsg="")
Function used for writing all lines stored in queue babLine to log with name logFileName.
Definition: logger.cpp:138
OUTSTREAM_VERB
Enum for controlling the output and writing level of MAiNGO (i.e., where should the output be written...
Definition: settings.h:44
std::queue< std::string > babLineCsv
Definition: logger.h:218
unsigned int _nSettingFiles
Definition: logger.h:232
Definition: logger.h:50
Definition: logger.h:53
This class contains all logging and output information.
Definition: logger.h:100
Definition: logger.h:41
Definition: logger.h:82
Definition: logger.h:38
Definition: logger.h:88
Definition: logger.h:52
Definition: logger.h:66
Definition: logger.h:84
Definition: logger.h:45
std::string csvIterationsName
Definition: logger.h:221
Definition: logger.h:64
Definition: logger.h:48
Definition: logger.h:72
void print_message(const std::string &message, bool writeLog, VERB verbosityGiven, VERB verbosityNeeded, OUTSTREAM_VERB givenOutstreamVerbosity)
The main function used for printing a given message and storing it in log and/or csv.
Definition: logger.cpp:29
Logger & operator=(const Logger &)=default
Default copy assignment.
Definition: logger.h:80
Definition: logger.h:70
namespace holding all essentials of MAiNGO
Definition: aleModel.h:31
Definition: logger.h:62
void create_log_file(bool writeLog, OUTSTREAM_VERB givenOutstreamVerbosity)
Function used for creating the log file.
Definition: logger.cpp:86
Definition: logger.h:56
Definition: logger.h:81
Definition: logger.h:68
VERB
Enum for controlling the output level of solvers (i.e., how much should be printed on the screen and,...
Definition: settings.h:33
std::string resFileName
Definition: logger.h:220
void create_csv_files(bool pureMultistart, bool printEveryLocalSearch, unsigned int maxLocalSearches, const std::vector< double > &objectivesAtRoot, const std::vector< SUBSOLVER_RETCODE > &feasibleAtRoot)
Function used for creating the csv files.
Definition: logger.cpp:99
Definition: logger.h:89
Definition: logger.h:83
Definition: logger.h:75
Definition: logger.h:87
Definition: logger.h:73
Definition: logger.h:51
void set_output_stream(std::ostream *outputStream)
Sets output stream.
Definition: logger.cpp:77
void write_all_iterations_to_csv(const std::string &errmsg="")
Function used for writing all lines stored in queue babCsv to csv file with name csvIterationsName.
Definition: logger.cpp:156
Definition: logger.h:91
Definition: logger.h:85
Definition: logger.h:76
void print_message_to_stream_only(const std::string &message, OUTSTREAM_VERB givenOutstreamVerbosity)
The main function used for printing a given message and storing it in log and/or csv.
Definition: logger.cpp:66
Definition: logger.h:77
void print_settings(bool writeLog, VERB verbosityGiven, VERB verbosityNeeded, OUTSTREAM_VERB givenOutstreamVerbosity)
Function for printing and writing user-set settings.
Definition: logger.cpp:219
void clear()
Clears all logging information.
Definition: logger.cpp:251
Definition: logger.h:71
Definition: logger.h:61
Definition: logger.h:43
Definition: logger.h:79
Definition: logger.h:65
Definition: logger.h:44
~Logger()
Default destructor.
Definition: logger.h:121