Transit Planner
1.0
An experiment on transfer patterns robustness
|
00001 // Copyright 2011: Eugen Sawin, Philip Stahl, Jonas Sternisko 00002 #ifndef SRC_LOGGER_H_ 00003 #define SRC_LOGGER_H_ 00004 00005 #include <boost/thread/shared_mutex.hpp> 00006 #include <string> 00007 #include <fstream> 00008 #include <iostream> 00009 #include <map> 00010 #include "./Clock.h" 00011 00012 using std::string; 00013 using std::ofstream; 00014 using std::ostream; 00015 using std::map; 00016 00017 class Logger { 00018 public: 00019 Logger(); 00020 Logger(const Logger& other); 00021 ~Logger(); 00022 00023 Logger& operator=(const Logger& other); 00024 00025 // Returns wether the logging is enabled. 00026 bool enabled() const; 00027 00028 // Sets the logging state. 00029 void enabled(const bool state); 00030 00031 // Sets the logger target file. 00032 // Empty ("") path redirects output to stdout. 00033 void target(const std::string& path); 00034 00035 // Resets the logger target to stdout. 00036 void reset(); 00037 00038 // Logs a debug message. 00039 void debug(const std::string& text) const; 00040 void debug(const char* format, ...) const; 00041 00042 // Logs a runtime info message. 00043 void info(const std::string& text) const; 00044 void info(const char* format, ...) const; 00045 00046 // Logs a runtime error message. 00047 void error(const std::string& text) const; 00048 void error(const char* format, ...) const; 00049 00050 // Returns a timer id used for performance measurements. 00051 // Starts the timer. 00052 int beginPerf(); 00053 00054 // Logs a performance message. The elapsed time since the call to 00055 // beginPerformance is measured for the given timer id. 00056 // Setting iter will additionally log the average time per iteration. 00057 // Returns the total elapsed time in seconds. 00058 double endPerf(const int id, const string& text = "", const int iter = 1); 00059 00060 // Returns a timer id used for progress measurements. 00061 // Starts the timer. 00062 int beginProg(); 00063 00064 // Logs a progress message. 00065 // Returns the estimated time to complete in seconds. 00066 double prog(const int id, const int finished, const int total, 00067 const string& text, const int numWorkers = 1); 00068 00069 // Logs the final progress message. 00070 // Returns the total elapsed time in seconds. 00071 double endProg(const int id, const string& text); 00072 00073 private: 00074 string path_; 00075 ostream* _stream; 00076 map<int, base::Clock> timers_; 00077 int timer_counter_; 00078 bool enabled_; 00079 boost::shared_mutex _mutex; 00080 }; 00081 00082 // The global instance of the logger. 00083 static Logger LOG; 00084 00085 #endif // SRC_LOGGER_H_