Go to the documentation of this file.00001
00019 #ifndef __LOGFILE
00020
00021 #define __LOGFILE
00022
00023 #include <string.h>
00024
00025 #define LOG_MSG_NO_ERROR_VERBOSE 5
00026 #define LOG_MSG_ERROR_VERBOSE 1
00027 #define LOG_MSG_ERROR_SEVERE 0
00028
00029
00030 #define LOG(format, ...) { char buffer[1024]; snprintf(buffer, 1024, format, ## __VA_ARGS__); std::string str = buffer; globalLog.writeLine(str); printf(format, ## __VA_ARGS__); }
00031
00032 #define LOG_MSG(index, format, ...) { if (index <= globalLog.debugLevel) { char buffer[1024]; snprintf(buffer, 1024, format, ## __VA_ARGS__); std::string str = buffer; globalLog.writeLine(str); printf(format, ## __VA_ARGS__); } }
00033
00034 #define LOG_VERBOSE(format, ...) { if (LOG_MSG_NO_ERROR_VERBOSE <= globalLog.debugLevel) { char buffer[1024]; snprintf(buffer, 1024, format, ## __VA_ARGS__); std::string str = buffer; globalLog.writeLine(str); printf(format, ## __VA_ARGS__); } }
00035
00036 #define LOG_ERROR(format, ...) { if (LOG_MSG_ERROR_VERBOSE <= globalLog.debugLevel) { char buffer[1024]; snprintf(buffer, 1024, format, ## __VA_ARGS__); std::string str = buffer; globalLog.writeLine(str); printf(format, ## __VA_ARGS__); } }
00037
00038 #define LOG_ERROR_SEVERE(format, ...) { if (LOG_MSG_ERROR_SEVERE <= globalLog.debugLevel) { char buffer[1024]; snprintf(buffer, 1024, format, ## __VA_ARGS__); std::string str = buffer; globalLog.writeLine(str); printf(format, ## __VA_ARGS__); } }
00039
00040
00041 #define LOG_MSG_LEVEL(index) (index <= globalLog.debugLevel)
00042 #define LOG_INPUT_LEVEL(index) (index <= globalLog.inputLevel)
00043
00044 class CLog
00045 {
00046 private:
00047 std::string filename, path;
00048 public:
00049 int debugLevel;
00050 int inputLevel;
00051 static std::string getTimeAsStr();
00052
00053 CLog();
00054 static std::string generateLogname(std::string path);
00055 void setFilename(std::string filename);
00056 void writeLine(std::string line, bool append = true);
00057
00058 void setDebugLevel(int debugLevel);
00059 void setInputLevel(int inputLevel);
00060 };
00061
00062
00063 extern CLog globalLog;
00064
00065 #endif