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 #ifndef VRS_LOGGER
00030 #define VRS_LOGGER
00031
00032 #include <vrs/sharedobj.h>
00033 #include <vrs/exception.h>
00034
00035 namespace VRS {
00036 class File;
00037
00039
00048
00049 class VRS_CORE_API Logger : public VRS::SharedObj {
00050 public:
00052 static SO<Logger> get();
00053
00056 static void setLogFileLocation(const std::string& dir);
00057
00060 static void setLogFilePrefix(const std::string& prefix);
00061
00064 static void setLogFileExtension(const std::string& extension);
00065
00068 static void enableLogToConsole(bool enable);
00069
00070 void logInfo(const std::string& component, const std::string& message);
00071 void logException(const std::string& component, const std::exception& exception);
00072 void logException(const std::string& component, std::exception* exception);
00073 void logError(int errortype, const char* expr, const char* file, int line, const char* text);
00074
00075 private:
00076
00077 static SO<Logger> g_instance;
00078 static std::string g_logFileDir;
00079 static std::string g_logFilePrefix;
00080 static std::string g_logFileExtension;
00081 static bool g_logToConsole;
00082
00083
00084 Logger(const std::string& dir, const std::string& prefix, const std::string& extension, bool logToConsole);
00085 void log(const std::string& component, const std::string& message);
00086
00087 SO<File> file_;
00088 std::string logFileDir_;
00089 std::string logFilePrefix_;
00090 std::string logFileExtension_;
00091 std::string processID_;
00092 bool logToConsole_;
00093 };
00094
00095 }
00096
00098 #define VRS_LOG(component, message) \
00099 std::ostringstream ostr; \
00100 ostr << message; \
00101 ::VRS::Logger::get()->logInfo(component, ostr.str())
00102
00104 #define VRS_LOG_EXCEPTION(component, stdexception) \
00105 ::VRS::Logger::get()->logException(component, stdexception)
00106
00108 #define VRS_LOG_ERROR(errortype, expr, file, line, text) \
00109 ::VRS::Logger::get()->logError(errortype, expr, file, line, text)
00110
00111 #endif // VRS_LOGGER