VERB_code_2.2  2
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
Output.cpp
Go to the documentation of this file.
1 /**
2  * \file Output.cpp
3  * \brief Logging and screen output function defenitions. see namespace Output for details
4  *
5  * \todo
6  * - Rewrite type conversion functions as "any to string" and organize them.
7  * - Move all headers to the header files and code to cpp files (if it is possible everywhere).
8  * - Rewrite all output with streams insted of old-c functions.
9  *
10  * \author Developed by Dmitry Subbotin under supervision of the PI Yuri Shprits
11  */
12 
13 #include "Output.h"
14 
15 namespace Output {
16 
17  /// \brief stream for log file defined in namespase Output
18  ofstream log_file;
19 
20  /// \brief verbose level defined in namespase Output
21  int outputLvl = 0;
22 
23  void open_log_file(string filename){
24  log_file.open(filename.c_str(), ios::out);
25  if (log_file == NULL) {
26  char buffer[1024];
27  strcpy(buffer, "error open file for output");
28  throw error_msg("FOPEN", "%s", buffer);
29  }
30  }
31 
33  log_file.close();
34  }
35 
37  log_file.flush();
38  }
39 
40  void set_output_lvl(int new_outputLvl){
41  outputLvl = new_outputLvl;
42  }
43 
44  void echo(int msglvl, const char * format , ... ) {
45  if (outputLvl >= msglvl) {
46  int len;
47  va_list args;
48  va_start( args, format );
49  char *buffer = new char[1024];
50 
51  len = vsnprintf(buffer, 1024, format, args ) + 1;
52  if (len == 0) throw error_msg("OUTPUT", "Output does not work :-(");
53 
54  (log_file) << buffer;
55  cout << buffer;
56 
57  delete buffer;
58  } else {
59  return;
60  }
61  }
62 
63 }