00001 00012 #include "Output.h" 00013 00014 namespace Output { 00015 00016 ofstream *log_file; 00017 int outputLvl = 0; 00018 00019 00020 void open_log_file(string filename){ 00021 log_file = new ofstream(filename.c_str()); 00022 if (log_file == NULL) { 00023 char buffer[1024]; 00024 strcpy(buffer, "error open file for output"); 00025 throw error_msg("FOPEN", "%s", buffer); 00026 } 00027 } 00028 00029 void close_log_file(){ 00030 (*log_file).close(); 00031 } 00032 00033 void set_output_lvl(int new_outputLvl){ 00034 outputLvl = new_outputLvl; 00035 } 00036 00037 void echo(int msglvl, const char * format , ... ) { 00038 if (outputLvl >= msglvl) { 00039 int len; 00040 va_list args; 00041 va_start( args, format ); 00042 char *buffer = new char[1024]; 00043 00044 len = vsnprintf(buffer, 1024, format, args ) + 1; 00045 if (len == 0) throw error_msg("OUTPUT", "Output does not work :-("); 00046 00047 (*log_file) << buffer; 00048 cout << buffer; 00049 00050 delete buffer; 00051 } else { 00052 return; 00053 } 00054 } 00055 00056 }