00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef LOGFILE_HPP_
00031 #define LOGFILE_HPP_
00032
00033 #include <string>
00034 #include "OutputFileHandler.hpp"
00035 #include <iostream>
00036 #include <cassert>
00037 #include <iomanip>
00038
00067 class LogFile
00068 {
00069 private:
00071 static LogFile* mpInstance;
00073 bool mFileSet;
00075 out_stream mpOutStream;
00076
00077 time_t mInitTime;
00078
00080 unsigned mLevel;
00081
00083 static const unsigned mMaxLoggingLevel = 2;
00084
00086 unsigned mPrecision;
00087
00091 LogFile();
00092
00093 public:
00097 static LogFile* Instance();
00098
00099 static unsigned Level();
00100
00117 void Set(unsigned level, std::string directory, std::string fileName="log.txt");
00118
00120 static unsigned MaxLoggingLevel();
00121
00128 void SetPrecision(unsigned precision);
00129
00137 void WriteHeader(std::string simulationType="");
00138
00144 void WriteElapsedTime(std::string pre="");
00145
00149 static void Close();
00150
00154 bool IsFileSet();
00155
00160 template <class T>
00161 LogFile& operator<<(T message)
00162 {
00163 if (mFileSet)
00164 {
00165 (*mpOutStream) << std::setprecision((int)mPrecision) << message << std::flush;
00166 }
00167
00168 return *this;
00169 }
00170 };
00171
00172
00173
00174 #define LOG(level, message) assert(level>0); if(level <= LogFile::Level()) { (*LogFile::Instance()) << message << "\n"; }
00175 #define LOG_AND_COUT(level, message) {std::cout << message << std::endl << std::flush; LOG(level, message); }
00176
00177
00178 #endif