00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <iostream>
00020 #include <fstream>
00021 #include "MrsLog.h"
00022 #include "common.h"
00023
00024 using std::ostringstream;
00025 using std::cout;
00026 using std::endl;
00027
00028
00029 using namespace Marsyas;
00030
00031 mrs_string MrsLog::fname_ = "marsyas.log";
00032 bool MrsLog::warnings_off_ = false;
00033 bool MrsLog::messages_off_ = false;
00034
00035
00036 void
00037 MrsLog::setLogFile(mrs_string fname)
00038 {
00039 fname_ = fname;
00040 }
00041
00042 void
00043 MrsLog::mrsMessage(const ostringstream& oss)
00044 {
00045 #ifdef MARSYAS_LOG_MESSAGES
00046 if (!messages_off_)
00047 {
00048 #ifdef MARSYAS_LOG2STDOUT
00049 cout << "[MRS_MESSAGE] " << oss.str() << endl;
00050 #endif
00051
00052 #ifdef MARSYAS_LOG2STDERR
00053 cerr << "[MRS_MESSAGE] " << oss.str() << endl;
00054 #endif
00055
00056 #ifdef MARSYAS_LOG2FILE
00057 ofstream ofs(fname_.c_str(), ios::out | ios::app);
00058 if (ofs.fail())
00059 return;
00060 if (!(ofs << "[MRS_MESSAGE] " << oss.str() << endl))
00061 {
00062 ofs.close();
00063 return;
00064 }
00065 ofs.close();
00066 return;
00067
00068 #endif
00069 }
00070
00071
00072 #else
00073 ;
00074 #endif
00075
00076 }
00077
00078
00079
00080 void
00081 MrsLog::mrsErr(const ostringstream& oss)
00082 {
00083
00084 #ifdef MARSYAS_LOG_ERRORS
00085
00086 #ifdef MARSYAS_LOG2STDOUT
00087 cout << "[MRSERR] " << oss.str() << endl;
00088 #endif
00089
00090 #ifdef MARSYAS_LOG2STDERR
00091 cerr << "[MRSERR] " << oss.str() << endl;
00092 #endif
00093
00094 #ifdef MARSYAS_LOG2FILE
00095 ofstream ofs(fname_.c_str(), ios::out | ios::app);
00096 if (ofs.fail())
00097 return;
00098 if (!(ofs << "[MRSERR] " << oss.str() << endl))
00099 {
00100 ofs.close();
00101 return;
00102 }
00103 ofs.close();
00104 return;
00105 #endif
00106
00107 #else
00108
00109 return;
00110 #endif
00111 }
00112
00113 void
00114 MrsLog::mrsWarning(const ostringstream& oss)
00115 {
00116 #ifdef MARSYAS_LOG_WARNINGS
00117 if (!warnings_off_)
00118 {
00119 #ifdef MARSYAS_LOG2STDOUT
00120 cout << "[MRS_WARNING] " << oss.str() << endl;
00121 #endif
00122
00123 #ifdef MARSYAS_LOG2STDERR
00124 cerr << "[MRS_WARNING] " << oss.str() << endl;
00125 #endif
00126
00127 #ifdef MARSYAS_LOG2FILE
00128 ofstream ofs(fname_.c_str(), ios::out | ios::app);
00129 if (ofs.fail())
00130 return;
00131 if (!(ofs << "[MRS_WARNING] " << oss.str() << endl))
00132 {
00133 ofs.close();
00134 return;
00135 }
00136 ofs.close();
00137 return;
00138
00139 #endif
00140 }
00141
00142
00143 #else
00144 ;
00145 #endif
00146
00147 }
00148
00149 void
00150 MrsLog::mrsDiagnostic(const ostringstream& oss)
00151 {
00152 #ifdef MARSYAS_LOG_DIAGNOSTICS
00153
00154 #ifdef MARSYAS_LOG2STDOUT
00155 cout << "[MRS_DIAG] " << oss.str() << endl;
00156 #endif
00157
00158
00159 #ifdef MARSYAS_LOG2STDERR
00160 cerr << "[MRS_DIAG] " << oss.str() << endl;
00161 #endif
00162
00163 #ifdef MARSYAS_LOG2FILE
00164 ofstream ofs(fname_.c_str(), ios::out | ios::app);
00165 if (ofs.fail())
00166 return;
00167 if (!(ofs << "[MRS_DIAG] " << oss.str() << endl))
00168 {
00169 ofs.close();
00170 return;
00171 }
00172 ofs.close();
00173 return;
00174 #endif
00175
00176 #else
00177 (void) oss;
00178 #endif
00179
00180
00181 }
00182
00183 void
00184 MrsLog::mrsDebug(const ostringstream& oss)
00185 {
00186 #ifdef MARSYAS_LOG2STDOUT
00187 cout << "[MRS_DEBUG] " << oss.str() << endl;
00188 #endif
00189
00190 #ifdef MARSYAS_LOG2STDERR
00191 cerr << "[MRS_DEBUG] " << oss.str() << endl;
00192 #endif
00193
00194
00195 #ifdef MARSYAS_LOG2FILE
00196 ofstream ofs(fname_.c_str(), ios::out | ios::app);
00197 if (ofs.fail())
00198 return;
00199 if (!(ofs << "[MRS_DEBUG] " << oss.str() << endl))
00200 {
00201 ofs.close();
00202 return;
00203 }
00204 ofs.close();
00205 return;
00206 #endif
00207 }
00208
00209 void
00210 MrsLog::mrsAssert(const char *strFile, unsigned uLine)
00211 {
00212 #ifdef MARSYAS_ASSERTS
00213 fflush(NULL);
00214 fprintf(stderr, "\nMARSYAS Assertion failed: %s, line %u\n",
00215 strFile, uLine);
00216 fflush(stderr);
00217 abort();
00218 #else
00219 (void) strFile;
00220 (void) uLine;
00221 #endif
00222 }