Go to the documentation of this file.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 LOGGER_HPP
00030 #define LOGGER_HPP
00031
00032 #include <boost/thread.hpp>
00033 #include <fstream>
00034 #include <string>
00035 #include <stdint.h>
00036
00037 #include "Portability.hpp"
00038
00039 class DllExport Logger {
00040 public:
00041 static const int CONSOLE=0x1;
00042 static const int FILE=0x2;
00043 static const int SYNC=0x4;
00044
00045 static const std::string currentDateTime();
00046 static double currentTimeMilliSecs();
00047 static double currentTimeMicroSecs();
00048
00049 public:
00050 Logger(const std::string& name);
00051 virtual ~Logger();
00052 void setMode(uint8_t mode);
00053
00054 void debug(const std::string& msg);
00055 void info(const std::string& msg);
00056 void warn(const std::string& msg);
00057 void error(const std::string& msg);
00058 void fatal(const std::string& msg);
00059
00060 private:
00061 void logit(const std::string& prefix, const std::string& msg, std::ostream& out, uint8_t mode);
00062 void tryOpen();
00063
00064 private:
00065 boost::mutex mMutex;
00066 std::ofstream mLog;
00067 std::string mName;
00068 uint8_t mMode;
00069 bool mOpened;
00070 };
00071
00072 #define logError(msg) error(msg)
00073 #define logFatal(msg) fatal(msg)
00074
00075 #ifdef NPL_DEBUG
00076 #define logDebug(msg) debug(msg)
00077 #define logInfo(msg) info(msg)
00078 #define logWarn(msg) debug(msg)
00079 #elif NPL_INFO
00080 #define logDebug(msg)
00081 #define logInfo(msg) info(msg)
00082 #define logWarn(msg) warn(msg)
00083 #elif NPL_WARN
00084 #define logDebug(msg)
00085 #define logInfo(msg)
00086 #define logWarn(msg) warn(msg)
00087 #endif
00088
00089 #endif