VERB_code_2.3
Output.cpp
Go to the documentation of this file.
1 
13 #include "Output.h"
14 
15 namespace Output {
16 
18  ofstream log_file;
19 
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 }
ofstream log_file
stream for log file defined in namespase Output
Definition: Output.cpp:18
void set_output_lvl(int new_outputLvl)
Set the verbose level until redefine.
Definition: Output.cpp:40
int outputLvl
verbose level defined in namespase Output
Definition: Output.cpp:21
functions for write log and support files. Functions are defined in Output.h and descripted in Output...
Definition: Output.cpp:15
void echo(int msglvl, const char *format,...)
Basic function! Write the message to the file.
Definition: Output.cpp:44
void open_log_file(string filename)
Open file stream for log file.
Definition: Output.cpp:23
void flush_log_file()
flush file stream for log file
Definition: Output.cpp:36
Logging and screen output. see namespace Output for details.
void close_log_file()
Close file stream for log file.
Definition: Output.cpp:32
Error message - stack of single_errors.
Definition: error.h:54