//============================================================================ // $Id: Logger.h,v 1.5 2008-03-05 11:36:27 messineo Exp $ // Description : //============================================================================ #ifndef LOGGER_H_ #define LOGGER_H_ #include #include #include namespace PamOffLineSW{ class LogUtil{ public: enum logLevel{ LOGERROR=0, LOGWARN, LOGINFO, LOGALL }; LogUtil(std::string& filename, logLevel level); LogUtil(std::string& filename); LogUtil(char* filename,logLevel level); LogUtil(char* filename); void setLoglevel(logLevel level); std::string& getLogFileName(); void logError(std::string& msg); void logWarning(std::string& msg); void logInfo(std::string& msg); void logAll(std::string& msg); void logAlways(std::string& msg); void logAlways(char* msg); void logError(char* msg); void logWarning(char* msg); void logInfo(char* msg); void logAll(char* msg); void appendLog(char* msg){mtempstring+=msg;}; void flushLog(logLevel level){ if(level == LOGERROR) logError(mtempstring); if(level == LOGWARN) logError(mtempstring); if(level == LOGINFO) logError(mtempstring); mtempstring+""; }; ~LogUtil(); template std::string value2string(T& val) { std::ostringstream os; os << val; return os.str(); } private: std::string mFilename; std::ofstream mOutStream; std::string mtempstring; logLevel mLevel; }; class Logger{ public: Logger(); Logger(bool autoflush); //currently not used ~Logger(); bool setLogFile(std::string& fileName); bool setLogFile(char* fileName); std::string& getLogFileName(); //TODO: this need to be checked template bool logValue(T& val) { mOutStream << val; return checkOutFileStreamError(Logger::LOG_MSG_OPERATION); } bool logENDL(); bool logMsg(std::string&); bool logMsg(char* charstar, int lenght); bool logMsg(char* charstar, long int lenght); //If the charstar buffer is null terminated bool logMsg(char* charstar_nullterminated); bool close(); std::ofstream& getOutStream(); //void setToBeflushedMemorySize(long charCountSize); private: bool checkOutFileStreamError(int operationKind,std::string& optionalMsg); bool checkOutFileStreamError(int operationKind); std::string mFileName; std::string mDummyOptionalMsg; std::string mBlankString; std::string mUnableToOpenFileMsg; std::string mUnableToLogMsg; std::string mToFileMsg; std::string mUnableToCloseMsg; std::string mFileMsg; std::ofstream mOutStream; bool mAutoFlush;//currently not used. it is here for future improvements, if any static const int OPEN_FILE_OPERATION; static const int LOG_MSG_OPERATION; static const int CLOSE_FILE_OPERATION; void initStringMsg(); }; } #endif /*LOGGER_H_*/